This is a PowerShell command to stop the automatic reboot that SCCM pushes out when updating a computer.
Source: https://happysccm.com/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' |
About Tom DeMeulenaere
Highly accomplished information technology professional with extensive knowledge in System Center Configuration Manager, Windows Server, SharePoint, and Office 365.
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.