Enable and disable scheduled task with PowerShell and variable

2

if I try to enable and disable a scheduled task with PowerShell this works.

Enable-ScheduledTask -TaskName "Name of my task"
Disable-ScheduledTask -TaskName "Name of my task"

But if I'm trying this with a variable I'll got an error.

$TaskName = "Name of my task"

Enable-ScheduledTask -TaskName "${TaskName}"
Disable-ScheduledTask -TaskName "${TaskName}"

How could I do this with the variable?

Edit:

This error occurs.

Enable-ScheduledTask : Das System kann die angegebene Datei nicht finden. (The system could not found the file)
+ Enable-ScheduledTask -TaskName "${TaskName}"
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (PS_ScheduledTask:Root/Microsoft/...S_ScheduledTask) [Enable-ScheduledTask], CimException
    + FullyQualifiedErrorId : HRESULT 0x80070002,Enable-ScheduledTask
powershell
scheduled-task
asked on Server Fault May 16, 2018 by mburm • edited May 16, 2018 by mburm

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0