I'm trying to remove schedule task on remote servers.
Invoke-Command -ComputerName "name" {Unregister-ScheduledTask -TaskName $task -WhatIf}
I get the following error
Cannot validate argument on parameter 'TaskName'. The argument is null. Provide a valid value for the argument, and then try running the command again. + CategoryInfo : InvalidData: (:) [Unregister-ScheduledTask], ParameterBindingValidationException + FullyQualifiedErrorId : ParameterArgumentValidationError,Unregister-ScheduledTask + PSComputerName : name
$Task='task'
If I specify the "Taskname" in text and not variable it works.
Invoke-Command -ComputerName "name" {Unregister-ScheduledTask -TaskName "task" -WhatIf}
What if: Performing operation 'Delete' on Target '\task'.