Install code for OOB patch Jan 2026 for windows 11 devices (4.1.8)

Thought I would share my code here for anyone to reuse for the OOB Jan 26 windows patch

## <Perform Installation tasks here>

$buildAndRevision = "$($envOSVersion.Build).$($envOSVersion.Revision)"
Write-ADTLogEntry -Message "revision and build equal $buildAndRevision"
$DownloadPath = 'C:\windows\Temp\msu'

switch ($buildAndRevision)
{
    #25h2
    '26200.7623'
    {$FileName = 'windows11.0-kb5077744-x64_fb63f62e4846b81b064c3515d7aff46c9d6d50c8.msu'
      $FullPath = Join-Path $DownloadPath $FileName
        if (-not (Test-Path -Path $FullPath)) 
        {
            #try to download patch
            Write-ADTLogEntry -Message "Downloading $FileName to $DownloadPath ..."
            try {
            #Download the MSU file
            $Url = 'https://catalog.sf.dl.delivery.mp.microsoft.com/filestreamingservice/files/aabb854a-0fe9-4caf-af00-d78fc1f8ddcb/public/windows11.0-kb5077744-x64_fb63f62e4846b81b064c3515d7aff46c9d6d50c8.msu'
            #download MSU to C:\windows\temp
            Show-ADTInstallationProgress -StatusMessage "Downloading out of band patch for 25h2...`nThe download time will vary on your internet connection" -WindowLocation topright -AllowMove
            Invoke-WebRequest -Uri $Url -OutFile $FullPath 
                }

        catch {
            Write-ADTLogEntry -Message "Failed to download MSU: $($_.Exception.Message)"
            exit 1
             }
        } 
            else {
            Write-ADTLogEntry -Message "File already exists: $FullPath"
                }

        #try to install patch       
        Show-ADTInstallationProgress -StatusMessage "Installing out of band patch for 25h2...`nThe install time is about 10 minutes" -WindowLocation 'topright' -AllowMove
        $arguments = "`"$FullPath`" /quiet /norestart"

        try {
                $process = Start-Process -FilePath "c:\windows\system32\wusa" -ArgumentList $arguments -Wait -PassThru -NoNewWindow
                if ($process.ExitCode -eq 0) {
                    Write-ADTLogEntry -Message "Installation completed successfully. A restart may still be required to finalize the update."
                    
                } 
                else 
                {
                    Write-ADTLogEntry -Message "wusa.exe exited with code $($process.ExitCode). Check CBS.log / Windows Update logs for details."
                }
            }
        catch 
        {
                Write-ADTLogEntry -Message "Failed to start wusa.exe: $($_.Exception.Message)"
                exit 1
        }
    }
    #24h2
    '26100.7623'
    {
        $FileName = 'windows11.0-kb5077744-x64_fb63f62e4846b81b064c3515d7aff46c9d6d50c8.msu'
        $FullPath = Join-Path $DownloadPath $FileName
        if (-not (Test-Path -Path $FullPath)) 
        {
            Write-ADTLogEntry -Message "Downloading $FileName to $DownloadPath ..."
            try {
            #Download the MSU file
            $Url = 'https://catalog.sf.dl.delivery.mp.microsoft.com/filestreamingservice/files/351cd910-6b58-4b15-85bb-6e9a25e5732f/public/windows11.0-kb5077744-x64_fb63f62e4846b81b064c3515d7aff46c9d6d50c8.msu'
            #download MSU to C:\windows\temp
            Show-ADTInstallationProgress -StatusMessage "Downloading out of band patch for 24h2...`nThe download time will vary on your internet connection" -WindowLocation topright -AllowMove
            Invoke-WebRequest -Uri $Url -OutFile $FullPath 
                }
                catch {
                    Write-ADTLogEntry -Message "Failed to download MSU: $($_.Exception.Message)"
                    exit 1
                    }
        } 
        else 
        {
            Write-ADTLogEntry -Message "File already exists: $FullPath"
        }

        #try to install patch
        Show-ADTInstallationProgress -StatusMessage "Installing out of band patch for 24h2...`nThe install time is about 10 minutes" -WindowLocation 'topright' -AllowMove
        $arguments = "`"$FullPath`" /quiet /norestart"

        try {
                $process = Start-Process -FilePath "c:\windows\system32\wusa" -ArgumentList $arguments -Wait -PassThru -NoNewWindow
                if ($process.ExitCode -eq 0) {
                    Write-ADTLogEntry -Message "Installation completed successfully. A restart may still be required to finalize the update."
                    
                } 
                else 
                {
                    Write-ADTLogEntry -Message "wusa.exe exited with code $($process.ExitCode). Check CBS.log / Windows Update logs for details."
                }
            }
        catch 
        {
                Write-ADTLogEntry -Message "Failed to start wusa.exe: $($_.Exception.Message)"
                exit 1
        } 
    }
    #23h2
    '22621.6491'
    {
        $FileName = 'windows11.0-kb5077797-x64_af2b9a9ab390d2081e3e4eb52a2f8b81b5be1d7f.msu'
        $FullPath = Join-Path $DownloadPath $FileName
        if (-not (Test-Path -Path $FullPath)) 
        {
            Write-ADTLogEntry -Message "Downloading $FileName to $DownloadPath ..."
            try {
            #Download the MSU file
            $Url = 'https://catalog.sf.dl.delivery.mp.microsoft.com/filestreamingservice/files/1a8be95a-a257-45cd-add6-b23c124ff8d3/public/windows11.0-kb5077797-x64_af2b9a9ab390d2081e3e4eb52a2f8b81b5be1d7f.msu'
            #download MSU to C:\windows\temp
            Show-ADTInstallationProgress -StatusMessage "Downloading out of band patch for 23h2...`nThe download time will vary on your internet connection" -WindowLocation topright -AllowMove
            Invoke-WebRequest -Uri $Url -OutFile $FullPath 
                }
                catch {
                    Write-ADTLogEntry -Message "Failed to download MSU: $($_.Exception.Message)"
                    exit 1
                    }
        } 
        else 
        {
            Write-ADTLogEntry -Message "File already exists: $FullPath"
        }

        #try to install patch
        Show-ADTInstallationProgress -StatusMessage "Installing out of band patch for 23h2...`nThe install time is about 10 minutes" -WindowLocation 'topright' -AllowMove
        $arguments = "`"$FullPath`" /quiet /norestart"

        try {
                $process = Start-Process -FilePath "c:\windows\system32\wusa" -ArgumentList $arguments -Wait -PassThru -NoNewWindow
                if ($process.ExitCode -eq 0) {
                    Write-ADTLogEntry -Message "Installation completed successfully. A restart may still be required to finalize the update."
                    
                } 
                else 
                {
                    Write-ADTLogEntry -Message "wusa.exe exited with code $($process.ExitCode). Check CBS.log / Windows Update logs for details."
                }
            }
        catch 
        {
                Write-ADTLogEntry -Message "Failed to start wusa.exe: $($_.Exception.Message)"
                exit 1
        } 
    }

}
1 Like
$build= "$($envOSVersion.Build)"
Write-ADTLogEntry -Message "revision and build equal $buildAndRevision"
$DownloadPath = 'C:\windows\Temp\msu'

switch ($build)
{
    #25h2
    '26200'
    {$FileName = 'windows11.0-kb5078127-x64_2669c24d8d8227e7992853d32fb4e95873bbe6bf.msu'
      $FullPath = Join-Path $DownloadPath $FileName
        if (-not (Test-Path -Path $FullPath)) 
        {
            #try to download patch
            Write-ADTLogEntry -Message "Downloading $FileName to $DownloadPath ..."
            try {
            #Download the MSU file
            $Url = 'https://catalog.sf.dl.delivery.mp.microsoft.com/filestreamingservice/files/df3e807e-9c9c-448e-93ce-63477b39d7f9/public/windows11.0-kb5078127-x64_2669c24d8d8227e7992853d32fb4e95873bbe6bf.msu'
            #download MSU to C:\windows\temp
            Show-ADTInstallationProgress -StatusMessage "Downloading out of band patch for 25h2...`nThe download time will vary on your internet connection" -WindowLocation topright -AllowMove
            Invoke-WebRequest -Uri $Url -OutFile $FullPath 
                }

        catch {
            Write-ADTLogEntry -Message "Failed to download MSU: $($_.Exception.Message)"
            exit 1
             }
        } 
            else {
            Write-ADTLogEntry -Message "File already exists: $FullPath"
                }

        #try to install patch       
        Show-ADTInstallationProgress -StatusMessage "Installing out of band patch for 25h2...`nThe install time is about 15 minutes" -WindowLocation 'topright' -AllowMove
        $arguments = "`"$FullPath`" /quiet /norestart"

        try {
                $process = Start-Process -FilePath "c:\windows\system32\wusa" -ArgumentList $arguments -Wait -PassThru -NoNewWindow
                if ($process.ExitCode -eq 0) {
                    Write-ADTLogEntry -Message "Installation completed successfully. A restart may still be required to finalize the update."
                    
                } 
                else 
                {
                    Write-ADTLogEntry -Message "wusa.exe exited with code $($process.ExitCode). Check CBS.log / Windows Update logs for details."
                }
            }
        catch 
        {
                Write-ADTLogEntry -Message "Failed to start wusa.exe: $($_.Exception.Message)"
                exit 1
        }
    }

    #24h2
    '26100'
    {
        $FileName = 'windows11.0-kb5078127-x64_2669c24d8d8227e7992853d32fb4e95873bbe6bf.msu'
        $FullPath = Join-Path $DownloadPath $FileName
        if (-not (Test-Path -Path $FullPath)) 
        {
            Write-ADTLogEntry -Message "Downloading $FileName to $DownloadPath ..."
            try {
            #Download the MSU file
            $Url = 'https://catalog.sf.dl.delivery.mp.microsoft.com/filestreamingservice/files/df3e807e-9c9c-448e-93ce-63477b39d7f9/public/windows11.0-kb5078127-x64_2669c24d8d8227e7992853d32fb4e95873bbe6bf.msu'
            #download MSU to C:\windows\temp
            Show-ADTInstallationProgress -StatusMessage "Downloading out of band patch for 24h2...`nThe download time will vary on your internet connection" -WindowLocation topright -AllowMove
            Invoke-WebRequest -Uri $Url -OutFile $FullPath 
                }
                catch {
                    Write-ADTLogEntry -Message "Failed to download MSU: $($_.Exception.Message)"
                    
                    exit 1
                    }
        } 
        else 
        {
            Write-ADTLogEntry -Message "File already exists: $FullPath"
        }

        #try to install patch
        Show-ADTInstallationProgress -StatusMessage "Installing out of band patch for 24h2...`nThe install time is about 15 minutes" -WindowLocation 'topright' -AllowMove
        $arguments = "`"$FullPath`" /quiet /norestart"

        try {
                $process = Start-Process -FilePath "c:\windows\system32\wusa" -ArgumentList $arguments -Wait -PassThru -NoNewWindow
                if ($process.ExitCode -eq 0) {
                    Write-ADTLogEntry -Message "Installation completed successfully. A restart may still be required to finalize the update."
                    
                } 
                else 
                {
                    Write-ADTLogEntry -Message "wusa.exe exited with code $($process.ExitCode). Check CBS.log / Windows Update logs for details."
                }
            }
        catch 
        {
                Write-ADTLogEntry -Message "Failed to start wusa.exe: $($_.Exception.Message)"
                exit 1
        } 
    }


    #23h2
    '22621'
    {
        $FileName = 'windows11.0-kb5078132-x64_143b061e4c6cd4784b9e0648280b5a2f707f8fb4.msu'
        $FullPath = Join-Path $DownloadPath $FileName
        if (-not (Test-Path -Path $FullPath)) 
        {
            Write-ADTLogEntry -Message "Downloading $FileName to $DownloadPath ..."
            try {
            #Download the MSU file
            $Url = 'https://catalog.sf.dl.delivery.mp.microsoft.com/filestreamingservice/files/483ab57f-e475-440e-a444-eff7b777a577/public/windows11.0-kb5078132-x64_143b061e4c6cd4784b9e0648280b5a2f707f8fb4.msu'
            #download MSU to C:\windows\temp
            Show-ADTInstallationProgress -StatusMessage "Downloading out of band patch for 23h2...`nThe download time will vary on your internet connection" -WindowLocation topright -AllowMove
            Invoke-WebRequest -Uri $Url -OutFile $FullPath 
                }
                catch {
                    Write-ADTLogEntry -Message "Failed to download MSU: $($_.Exception.Message)"
                    exit 1
                    }
        } 
        else 
        {
            Write-ADTLogEntry -Message "File already exists: $FullPath"
        }

        #try to install patch
        Show-ADTInstallationProgress -StatusMessage "Installing out of band patch for 23h2...`nThe install time is about 15 minutes" -WindowLocation 'topright' -AllowMove
        $arguments = "`"$FullPath`" /quiet /norestart"

        try {
                $process = Start-Process -FilePath "c:\windows\system32\wusa" -ArgumentList $arguments -Wait -PassThru -NoNewWindow
                if ($process.ExitCode -eq 0) {
                    Write-ADTLogEntry -Message "Installation completed successfully. A restart may still be required to finalize the update."
                    
                } 
                else 
                {
                    Write-ADTLogEntry -Message "wusa.exe exited with code $($process.ExitCode). Check CBS.log / Windows Update logs for details."
                }
            }
        catch 
        {
                Write-ADTLogEntry -Message "Failed to start wusa.exe: $($_.Exception.Message)"
                exit 1
        } 
    }
       

}
1 Like

Thank you for this Alan! Much appreciated mate will def be updating my current script with this

Updated code to add more error prompts for user

$build= "$($envOSVersion.Build)"
Write-ADTLogEntry -Message "revision and build equal $buildAndRevision"
$DownloadPath = 'C:\windows\Temp\msu'
if ((Test-Path $DownloadPath)) 
{
Remove-ADTFolder -Path $DownloadPath
}

if (-not (Test-Path $DownloadPath)) 
{
New-ADTFolder -LiteralPath $DownloadPath 
}

switch ($build)
{
    #25h2
    '26200'
    {$FileName = 'windows11.0-kb5078127-x64_2669c24d8d8227e7992853d32fb4e95873bbe6bf.msu'
      $FullPath = Join-Path $DownloadPath $FileName
        if (-not (Test-Path -Path $FullPath)) 
        {
            #try to download patch
            Write-ADTLogEntry -Message "Downloading $FileName to $DownloadPath ..."
            try {
            #Download the MSU file
            $Url = 'https://catalog.sf.dl.delivery.mp.microsoft.com/filestreamingservice/files/df3e807e-9c9c-448e-93ce-63477b39d7f9/public/windows11.0-kb5078127-x64_2669c24d8d8227e7992853d32fb4e95873bbe6bf.msu'
            #download MSU to C:\windows\temp
            Show-ADTInstallationProgress -StatusMessage "Downloading out of band patch for 25h2...`nThe download time will vary on your internet connection" -WindowLocation topright -AllowMove
            Invoke-WebRequest -Uri $Url -OutFile $FullPath 
                }

        catch {
            Write-ADTLogEntry -Message "Failed to download MSU: $($_.Exception.Message)"
            Show-ADTInstallationPrompt -Message "Failed to download patch: $($_.Exception.Message).Please reboot and reconnect to the network" -ButtonRightText 'OK'
            Close-ADTSession -ExitCode 1
             }
        } 
            else {
            Write-ADTLogEntry -Message "File already exists: $FullPath"
                }

        #try to install patch       
        Show-ADTInstallationProgress -StatusMessage "Installing out of band patch for 25h2...`nThe install time is about 15 minutes" -WindowLocation 'topright' -AllowMove
        $arguments = "`"$FullPath`" /quiet /norestart"

        try {
                $process = Start-Process -FilePath "c:\windows\system32\wusa" -ArgumentList $arguments -Wait -PassThru -NoNewWindow
                if ($process.ExitCode -eq 0 -or $process.ExitCode -eq 3010) {
                    Write-ADTLogEntry -Message "Installation completed successfully. A restart may still be required to finalize the update."
                    Show-ADTInstallationRestartPrompt -CountdownSeconds 3600
                    
                } 
                else 
                {
                    Write-ADTLogEntry -Message "wusa.exe exited with code $($process.ExitCode). Check CBS.log / Windows Update logs for details."
                    Show-ADTInstallationPrompt -Message "wusa.exe exited with code $($process.ExitCode). Please reboot and try the install again" -ButtonRightText 'OK'
                    Close-ADTSession -ExitCode 1
                }
            }
        catch 
        {
                Write-ADTLogEntry -Message "Failed to start wusa.exe: $($_.Exception.Message)"
                Show-ADTInstallationPrompt -Message "Failed to start wusa.exe: $($_.Exception.Message)" -ButtonRightText 'OK'
                Close-ADTSession -ExitCode 1
        }
    }

    #24h2
    '26100'
    {
        $FileName = 'windows11.0-kb5078127-x64_2669c24d8d8227e7992853d32fb4e95873bbe6bf.msu'
        $FullPath = Join-Path $DownloadPath $FileName
        if (-not (Test-Path -Path $FullPath)) 
        {
            Write-ADTLogEntry -Message "Downloading $FileName to $DownloadPath ..."
            try {
            #Download the MSU file
            $Url = 'https://catalog.sf.dl.delivery.mp.microsoft.com/filestreamingservice/files/df3e807e-9c9c-448e-93ce-63477b39d7f9/public/windows11.0-kb5078127-x64_2669c24d8d8227e7992853d32fb4e95873bbe6bf.msu'
            #download MSU to C:\windows\temp
            Show-ADTInstallationProgress -StatusMessage "Downloading out of band patch for 24h2...`nThe download time will vary on your internet connection" -WindowLocation topright -AllowMove
            Invoke-WebRequest -Uri $Url -OutFile $FullPath 
                }
                catch {
                    Write-ADTLogEntry -Message "Failed to download MSU: $($_.Exception.Message)"
                    Show-ADTInstallationPrompt -Message "Failed to download patch: $($_.Exception.Message).Please reboot and reconnect to the network" -ButtonRightText 'OK'
                    Close-ADTSession -ExitCode 1
                    }
        } 
        else 
        {
            Write-ADTLogEntry -Message "File already exists: $FullPath"
        }

        #try to install patch
        Show-ADTInstallationProgress -StatusMessage "Installing out of band patch for 24h2...`nThe install time is about 15 minutes" -WindowLocation 'topright' -AllowMove
        $arguments = "`"$FullPath`" /quiet /norestart"

        try {
                $process = Start-Process -FilePath "c:\windows\system32\wusa" -ArgumentList $arguments -Wait -PassThru -NoNewWindow
                if ($process.ExitCode -eq 0 -or $process.ExitCode -eq 3010) {
                    Write-ADTLogEntry -Message "Installation completed successfully. A restart may still be required to finalize the update."
                    Show-ADTInstallationRestartPrompt -CountdownSeconds 3600
                    
                } 
                else 
                {
                    Write-ADTLogEntry -Message "wusa.exe exited with code $($process.ExitCode). Check CBS.log / Windows Update logs for details."
                    Show-ADTInstallationPrompt -Message "wusa.exe exited with code $($process.ExitCode). Please reboot and try the install again" -ButtonRightText 'OK'
                    Close-ADTSession -ExitCode 1
                }
            }
        catch 
        {
                Write-ADTLogEntry -Message "Failed to start wusa.exe: $($_.Exception.Message)"
                Show-ADTInstallationPrompt -Message "Failed to start wusa.exe: $($_.Exception.Message)" -ButtonRightText 'OK'
                Close-ADTSession -ExitCode 1
        } 
    }


    #23h2
    '22621'
    {
        $FileName = 'windows11.0-kb5078132-x64_143b061e4c6cd4784b9e0648280b5a2f707f8fb4.msu'
        $FullPath = Join-Path $DownloadPath $FileName
        if (-not (Test-Path -Path $FullPath)) 
        {
            Write-ADTLogEntry -Message "Downloading $FileName to $DownloadPath ..."
            try {
            #Download the MSU file
            $Url = 'https://catalog.sf.dl.delivery.mp.microsoft.com/filestreamingservice/files/483ab57f-e475-440e-a444-eff7b777a577/public/windows11.0-kb5078132-x64_143b061e4c6cd4784b9e0648280b5a2f707f8fb4.msu'
            #download MSU to C:\windows\temp
            Show-ADTInstallationProgress -StatusMessage "Downloading out of band patch for 23h2...`nThe download time will vary on your internet connection" -WindowLocation topright -AllowMove
            Invoke-WebRequest -Uri $Url -OutFile $FullPath 
                }
                catch {
                    Write-ADTLogEntry -Message "Failed to download MSU: $($_.Exception.Message)"
                    Show-ADTInstallationPrompt -Message "Failed to download patch: $($_.Exception.Message).Please reboot and reconnect to the network" -ButtonRightText 'OK'
                    Close-ADTSession -ExitCode 1
                    }
        } 
        else 
        {
            Write-ADTLogEntry -Message "File already exists: $FullPath"
        }

        #try to install patch
        Show-ADTInstallationProgress -StatusMessage "Installing out of band patch for 23h2...`nThe install time is about 15 minutes" -WindowLocation 'topright' -AllowMove
        $arguments = "`"$FullPath`" /quiet /norestart"

        try {
                $process = Start-Process -FilePath "c:\windows\system32\wusa" -ArgumentList $arguments -Wait -PassThru -NoNewWindow
                if ($process.ExitCode -eq 0 -or $process.ExitCode -eq 3010) {
                    Write-ADTLogEntry -Message "Installation completed successfully. A restart may still be required to finalize the update."
                    Show-ADTInstallationRestartPrompt -CountdownSeconds 3600
                    
                } 
                else 
                {
                    Write-ADTLogEntry -Message "wusa.exe exited with code $($process.ExitCode). Check CBS.log / Windows Update logs for details."
                    Show-ADTInstallationPrompt -Message "wusa.exe exited with code $($process.ExitCode). Please reboot and try the install again" -ButtonRightText 'OK'
                    Close-ADTSession -ExitCode 1
                }
            }
        catch 
        {
                Write-ADTLogEntry -Message "Failed to start wusa.exe: $($_.Exception.Message)"
                Show-ADTInstallationPrompt -Message "Failed to start wusa.exe: $($_.Exception.Message)" -ButtonRightText 'OK'
                Close-ADTSession -ExitCode 1
        } 
    }
       

}