Method invocation failed because [System.String] doesn't contain a method named 'DeleteTask'
So, I took a look at the code found at ...\Documents\WindowsPowerShell\Modules\TaskScheduler\Remove-Task.ps1 and found an error. The version I have looks like this at lines 53-58:
switch ($psCmdlet.ParameterSetName) {
Task {
$scheduler = Connect-ToTaskScheduler -ComputerName $ComputerName -Credential $Credential
$folder =$scheduler.GetFolder("")
$folder.DeleteTask($task.Path, 0)
}
The problem is that there is a [String[]] $Folder = "" declaration earlier on in the code.
I changed it to the following and it looks like it works:
switch ($psCmdlet.ParameterSetName) {
Task {
$scheduler = Connect-ToTaskScheduler -ComputerName $ComputerName -Credential $Credential
$taskfolder =$scheduler.GetFolder("")
$taskfolder.DeleteTask($task.Path, 0)
}
Coincidentally, the Get-ScheduledTask.ps1 cmdlet uses the same idea so the original author must have just missed this. The module looks like it hasn't been updated for quite some time.
Thanks this helped me.
ReplyDelete