Questions & Answers

BrokenCimSession when stopping a scheduled task

When running the following on one of our Windows machine

$name = "My task"
Stop-ScheduledTask -TaskName $name -ErrorAction SilentlyContinue

I get this error:

Stop-ScheduledTask : Cannot connect to CIM server. The system cannot find the file specified.
+     Stop-ScheduledTask -TaskName $name -ErrorAction SilentlyContinue
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ResourceUnavailable: (PS_ScheduledTask:String) [Stop-ScheduledTask], CimJobException
    + FullyQualifiedErrorId : CimJob_BrokenCimSession,Stop-ScheduledTask

It does not look like a permission issus since it would look more like

Stop-ScheduledTask : Access is denied.
+     [void](Stop-ScheduledTask -TaskName $name -ErrorAction SilentlyContinue)
+            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : PermissionDenied: (PS_ScheduledTask:Root/Microsoft/...p_ScheduledTask) [Stop-Schedul
   edTask], CimException
    + FullyQualifiedErrorId : HRESULT 0x80070005,Stop-ScheduledTask
2023-01-19 00:00:03
Are you able to get the task? I.e.: Get-ScheduledTask?
Answers(0) :