Stopping mandatory SCCM Reboot last minute
Open an elevated powershell window and run the commands:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
#Clears Restart registry to stop SCCM restarting the machine Remove-Item -Path 'HKLM:\SOFTWARE\Microsoft\SMS\Mobile Client\Reboot Management\RebootData' Remove-Item -Path 'HKLM:\SOFTWARE\Microsoft\SMS\Mobile Client\Updates Management\Handler\UpdatesRebootStatus\*' Remove-ItemProperty -Name * -Path 'HKLM:\Microsoft\Windows\currentVersion\windowsupdate\Auto Update\RebootRequired' shutdown -a #Disable as it starts ccmexec back up Disable-ScheduledTask -TaskPath "Microsoft\Configuration Manager" -TaskName "Configuration Manager Passport for Work Certificate Enrollment Task" #Re-enable next boot $Action = New-ScheduledTaskAction -Execute "schtasks.exe" -Argument '/Change /TN "Microsoft\Configuration Manager\Configuration Manager Passport for Work Certificate Enrollment Task" /enable' $Trigger = New-ScheduledTaskTrigger -AtStartup; $Trigger.EndBoundary = (get-date).AddDays(90).ToString('s') $Settings = New-ScheduledTaskSettingsSet -DeleteExpiredTaskAfter 00:00:30 Register-ScheduledTask -Force -user SYSTEM -TaskName "Enable CM Passport Enrollment" -Action $Action -Trigger $Trigger -Settings $Settings Stop-Service ccmexec -Force |
To use it in a run script and get feedback we need to delay the restart of the service using scheduled task
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
Remove-Item -Path 'HKLM:\SOFTWARE\Microsoft\SMS\Mobile Client\Reboot Management\RebootData' Remove-Item -Path 'HKLM:\SOFTWARE\Microsoft\SMS\Mobile Client\Updates Management\Handler\UpdatesRebootStatus\*' Remove-ItemProperty -Name * -Path 'HKLM:\Microsoft\Windows\currentVersion\windowsupdate\Auto Update\RebootRequired' shutdown -a #Disable as it starts ccmexec back up Disable-ScheduledTask -TaskPath "Microsoft\Configuration Manager" -TaskName "Configuration Manager Passport for Work Certificate Enrollment Task" #Re-enable next boot $Action = New-ScheduledTaskAction -Execute "schtasks.exe" -Argument '/Change /TN "Microsoft\Configuration Manager\Configuration Manager Passport for Work Certificate Enrollment Task" /enable' $Trigger = New-ScheduledTaskTrigger -AtStartup; $Trigger.EndBoundary = (get-date).AddDays(90).ToString('s') $Settings = New-ScheduledTaskSettingsSet -DeleteExpiredTaskAfter 00:00:30 Register-ScheduledTask -Force -user SYSTEM -TaskName "Enable CM Passport Enrollment" -Action $Action -Trigger $Trigger -Settings $Settings $Action = New-ScheduledTaskAction -Execute "powershell.exe" -Argument '-command Stop-Service ccmexec -Force' $Trigger = New-ScheduledTaskTrigger -Once -At (get-date).AddSeconds(10); $Trigger.EndBoundary = (get-date).AddSeconds(60).ToString('s') $Settings = New-ScheduledTaskSettingsSet -StartWhenAvailable -DeleteExpiredTaskAfter 00:00:30 Register-ScheduledTask -Force -user SYSTEM -TaskName "Stop ccmexec" -Action $Action -Trigger $Trigger -Settings $Settings Write-Host 'Restart cancelled. CCMEXEC Service will stop in 10 seconds' |
Thanks @PotentEngineer and Russ for the code I mismashed together
After running the Script it is not possible to force timed restarts..
It can't find the biggest active service window....
The script stops the whole SCCM service for that session
Interested in More SCCM solutions