CmdLets/Master/Restart-OnPending.ps1

Function Restart-OnPending 
 {
<#
.SYNOPSIS
    Checks for pending system reboots caused by file rename operations and restarts the computer if found.
 
.DESCRIPTION
    The Restart-OnPending function inspects the Windows Registry across all Control Sets
    (under HKLM:\System\*Control*\Control\Session Manager) for pending file rename operations
    (PendingFileRenameOperations and FileRenameOperations). If any pending actions are detected,
    it pauses for a specified delay and initiates a system reboot using Restart-Computer.
 
.PARAMETER Delay
    The countdown delay in seconds before the computer reboots when pending operations are detected.
    Defaults to 15 seconds.
 
.EXAMPLE
    Restart-OnPending -Delay 30
     
    Description:
    Checks for pending file renames and, if found, waits 30 seconds before rebooting the system.
 
.NOTES
    Prerequisites:
    - Requires administrative privileges to read the system registry and restart the computer.
 
.LINK
    https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.management/restart-computer
#>

    [CmdletBinding()]
    Param(
        [Parameter()][Int32]$Delay=15
    )
    $ControlSets = Get-ChildItem "hklm:\system\*control*"
    $Properties = @(
        "PendingFileRenameOperations",
        "FileRenameOperations"
    )
    foreach ($ControlSet in $ControlSets) {
        $Path = (join-path $ControlSet "Control\Session Manager").Replace("HKEY_LOCAL_MACHINE","HKLM:")
        $Manager = Get-Item $Path
        $Properties | ForEach-Object { 
            If ($Manager.Property -Contains $_) {
                Write-Host "Pending operations detected, Rebooting in $Delay seconds"
                Write-Verbose "`t$($Manager.PSPath)"
                Write-Verbose "`t$_"
                Start-Sleep -Seconds $Delay
                Restart-Computer
            }
        }
    } 

}