Public/Install-CCMClientMissingPatches.ps1

function Install-CCMClientSoftwareUpdate {
    [cmdletbinding()]
    param (

        [Parameter(ValueFromPipeline = $true,
            ValueFromPipelineByPropertyName = $true,
            ParameterSetName = 'ComputerName',
            Position = 1,
            Mandatory = $true)]
        #[alias('Name')]
        [string[]]$ComputerName,

        [Parameter(ParameterSetName = 'ComputerName')]
        [PSCredential]$Credential
    )

    begin {
        $computerList = [System.Collections.Generic.List[string]]::new()

        #using SB here because these classes fail over WinRM (cim) currently. Will change to CIM if I find a workaround other than a DCOM session option
        $sbInstallUpdates = {
            $cimParm = @{
                NameSpace   = 'root/ccm/ClientSDK'
            }
            [ciminstance[]]$updates = Get-CimInstance -ClassName CCM_SoftwareUpdate @cimParm
            if ($updates) {
                Invoke-CimMethod @cimParm -ClassName CCM_SoftwareUpdatesManager -MethodName InstallUpdates -Arguments @{ CCMUpdates = $updates }
            }
            else {
                Write-Verbose "$env:COMPUTERNAME: no missing updates found"
            }
        }
    }

    process {
        $computerList.AddRange([string[]]$ComputerName)
    }
    end {
        $invokeParam = @{
            ComputerName = $computerList
            ScriptBlock = $sbInstallUpdates
        }
        if($Credential){
            $invokeParam['Credential'] = $Credential
        }
        Invoke-Command @invokeParam
    }
}