Having an issue unregistering my scheduled tasks on servers I have admin rights to.
$target = “servername”
$tasks = Invoke-Command -ComputerName $target -Scriptblock{Get-ScheduledTask -TaskName “TaskName”}
Write-host $tasks.TaskName //I outputted this to ensure the task DOES exist on the server and can confirm it does
$taskname = $tasks.TaskName
if ($tasks)
{
Write-Host “Scheduled task found”
$Session = New-CimSession $target
Unregister-ScheduledTask -Taskname $taskname -CimSession $Session -Confirm $false
}
Else
{
Write-Host “scheduled task not found”
}
So I know the task exists, but I get this error message:
Unregister-ScheduledTask : Servername: No matching MSFT_ScheduledTask objects found by CIM query for instances of the
Root/Microsoft/Windows/TaskScheduler/MSFT_ScheduledTask class on the Servername CIM server: SELECT * FROM MSFT_ScheduledTask WHERE ((TaskName LIKE ‘TaskName’))
AND ((TaskPath LIKE ‘False’)). Verify query parameters and retry.