Zum Inhalt
Kaffeeundcode
Skriptbibliothek
PowerShell 06.10.2026

PowerShell

Detect PendingReboot

049_Detect-PendingReboot.ps1

<#
.SYNOPSIS
    Prüft, ob ein Neustart ausstehend ist (Pending Reboot).
    (Intune Detection Script)

.DESCRIPTION
    <!-- library-status:start -->
    Prüfstatus: Ungeprüft
    Windows- und Tenant-Abnahme ausstehend; keine pauschale Produktionsfreigabe.

    <!-- library-status:end -->

    Prüft diverse Registry-Keys (Component Based Servicing, Windows Update, Session Manager).
    NonCompliant wenn ein Reboot nötig ist.

.NOTES
    File Name: 049_Detect-PendingReboot.ps1
    Author: Mattia Cirillo
    Version: 1.0
#>

try {
    $RebootPending = $false

    # 1. Component Based Servicing
    if (Test-Path "HKLM:SOFTWAREMicrosoftWindowsCurrentVersionComponent Based ServicingRebootPending") { $RebootPending = $true }

    # 2. Windows Update
    if (Test-Path "HKLM:SOFTWAREMicrosoftWindowsCurrentVersionWindowsUpdateAuto UpdateRebootRequired") { $RebootPending = $true }

    # 3. Session Manager
    $PendingFileRename = Get-ItemProperty -Path "HKLM:SYSTEMCurrentControlSetControlSession Manager" -Name PendingFileRenameOperations -ErrorAction SilentlyContinue
    if ($PendingFileRename) { $RebootPending = $true }

    if ($RebootPending) {
        Write-Host "NonCompliant (Reboot Pending)"
        exit 1
    } else {
        Write-Host "Compliant"
        exit 0
    }

} catch {
    Write-Error "Fehler: $_"
    exit 1
}