Do/Loop - SCCM Software Updates

Hi All,

I have the below script which I am using to run on critical desktop clients to install all available updates (quarterly) that have been deployed by SCCM.

As some deployed updates only become available when other dependent updates have been installed the script is stopping before the reboot.

I ideally want it to loop and continue to install all available updates until all have installed and then proceed to automatically reboot.

Any ideas?

Add-Type -AssemblyName PresentationCore, PresentationFramework

switch (
  [System.Windows.MessageBox]::Show(
    'This action will download and install critical Microsoft updates and may invoke an automatic reboot. Do you want to continue?',
    'WARNING',
    'YesNo',
    'Warning'
  )
) {
  'Yes' {
Start-Process -FilePath "C:\Windows\CCM\ClientUX\scclient.exe" "softwarecenter:Page=InstallationStatus"
$installUpdateParam = @{
        NameSpace = 'root/ccm/ClientSDK'
        ClassName = 'CCM_SoftwareUpdatesManager'
        MethodName = 'InstallUpdates'
    }

    $getUpdateParam = @{            
        NameSpace = 'root/ccm/ClientSDK'
        ClassName = 'CCM_SoftwareUpdate'
        Filter = 'EvaluationState < 8'
    }       

    [ciminstance[]]$updates = Get-CimInstance @getUpdateParam
    
    if ($updates) {
        Invoke-CimMethod @installUpdateParam  -Arguments @{ CCMUpdates = $updates } 
        
        while(Get-CimInstance @getUpdateParam){
            Start-Sleep -Seconds 30
        }
    }

    $rebootPending = Invoke-CimMethod -Namespace root/ccm/ClientSDK -ClassName CCM_ClientUtilities -MethodName DetermineIfRebootPending
    if ($rebootPending.RebootPending){
        Invoke-CimMethod -Namespace root/ccm/ClientSDK -ClassName CCM_ClientUtilities -MethodName RestartComputer
    }
    'No' 
    #  Exit-PSSession
  }
}

rayman16,
Welcome to the forum. :wave:t4:

We use to use the combination of these to functions to trigger the installation of all by SCCM advertised updates and to check the status of the installation. It might be helpful for you as well: