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
Best Answer
Just get rid of the curly brackets