restart-service -name ccmexec -force $maxwait = 120 #2 mins $pause = 5 $timer = 0 $exitcode = 1 #default = fail while ($timer -lt $maxwait) { start-sleep -Seconds $pause $check = (Get-Service -Name CcmExec).Status write-host $check if($check -eq "Running") { # Machine policy retrieval & Evaluation Cycle Invoke-WMIMethod -Namespace root\ccm -Class SMS_CLIENT -Name TriggerSchedule "{00000000-0000-0000-0000-000000000021}" # Software updates deployment evaluation cycle Invoke-WMIMethod -Namespace root\ccm -Class SMS_CLIENT -Name TriggerSchedule "{00000000-0000-0000-0000-000000000114}" # Hardware inventory cycle Invoke-WMIMethod -Namespace root\ccm -Class SMS_CLIENT -Name TriggerSchedule "{00000000-0000-0000-0000-000000000001}" # Discovery Data Collection Cycle Invoke-WMIMethod -Namespace root\ccm -Class SMS_CLIENT -Name TriggerSchedule "{00000000-0000-0000-0000-000000000003}" $exitcode = 0 $timer = $maxwait } else { $timer += $pause } } exit $exitcode