FeaturedPower ShellScripts

List Available Patches (windows update) – Remote machine

Use this script to check if a remote machine has any new windows update available


This script will list all available windows updates
User the Computer parameter to specify the Computer to remotely list  windows updates .

function install-OSUpdate {

        param (



                                                                                                                                                                                                                        ForEach ($c in $computer){

        #install pswindows updates module on remote machine
        [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
        $nugetinstall = invoke-command -ComputerName $c -ScriptBlock {Install-PackageProvider -Name NuGet -MinimumVersion -Force}

        invoke-command -ComputerName $c -ScriptBlock {
            [Net.ServicePointManager]::SecurityProtocol += [Net.SecurityProtocolType]::Tls12
            install-module pswindowsupdate -force

        invoke-command -ComputerName $c -ScriptBlock {Import-Module PSWindowsUpdate -force}

            #Reset Timeouts
            $connectiontimeout = 0
            $updatetimeout = 0
            #starts up a remote powershell session to the computer
                $session = New-PSSession -ComputerName $c
                "reconnecting remotely to $c"
                sleep -seconds 10
            } until ($session.state -match "Opened" -or $connectiontimeout -ge 10)

            #retrieves a list of available updates

            "Checking for new updates available on $c"

            $updates = invoke-command -session $session -scriptblock {Get-wulist -MicrosoftUpdate -verbose}

            #counts how many updates are available

            $updatenumber = ($updates.kb).count
            write-host "$updatenumber updates available"

            #if there are available updates proceed with installing the updates and then reboot the remote machine




        "Windows is now up to date on $c"




Show More

Related Articles

Back to top button