How to set a reboot pending flag in the registry
There are multiple registry flags that can be used to tell the system a reboot is pending, but in this post, I'm going to cover my most favorite way.
Why set a reboot flag?
Have you ever ran a cleanup script that you know you need to reboot the system afterwards but don't want to immediately reboot? Maybe you've used SCCM, Intune, or some other RMM tool to clean up a workstation or server in the background but you need to wait until a maintenance window or for the user to finish working. This is just one way to handle that process. If you're adding this code snippet into a larger script, be sure it goes in at the bottom and you've properly handled errors; ideally returning or exiting out before you reach this stage so the flag can double as the script completely successfully!The code to set the flag:
Run using an elevated PowerShell prompt...
New-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce" -Name "DVDRebootSignal" | Out-Null