install-sccmsoftwareupdates old code in v 3.2.0

Topics: Archive - General
Feb 11, 2015 at 10:22 PM
This may be addressed with newer versions but for those still on 3.2.0......

While working with cm12 r2 clients and the install-sccmsoftwareupdates it would simply not work. After some digging I found that on line ~4748 the error out code line was wrong

Write-Log "Trigger SCCM Install Updates failed: " + $_.Exception.Message

It would always wing an error but changing it to

Write-Log "Trigger SCCM Install Updates failed: $($_.Exception.Message)"

solved that problem but now the error tells me that the System.Management.ManagementObject class does not contain installupdates.

The code originally pointed to:

$SmsSoftwareUpdates = [wmiclass]"ROOT\ccm:SMS_Client"

which does not contain the right stuff.

However,

$SmsSoftwareUpdates = [wmiclass]"ROOT\ccm\ClientSDK:CCM_SoftwareUpdatesManager"

does and now looks to be all happy happy.

Below is the whole function as I have it today.


Function Install-SCCMSoftwareUpdates {
<#
.SYNOPSIS
Scans for outstanding SCCM updates to be installed and installed the pending updates
.DESCRIPTION
Scans for outstanding SCCM updates to be installed and installed the pending updates
This function can take several minutes to run
.EXAMPLE
Install-SCCMSoftwareUpdates
.PARAMETER ContinueOnError
Continue if an error is encountered
.NOTES
.LINK
Http://psappdeploytoolkit.codeplex.com

>

Param (
    [boolean] $ContinueOnError = $true
)

# Scan for updates
Write-Log "Scanning for SCCM Software Updates..."
Invoke-SCCMTask -ScheduleId "SoftwareUpdatesScan"

Write-Log "Sleeping 180 seconds..."
Sleep -Seconds 180

Write-Log "Installing pending software updates..."
Try {
    #$SmsSoftwareUpdates = [wmiclass]"ROOT\ccm:SMS_Client"
    $SmsSoftwareUpdates = [wmiclass]"ROOT\ccm\ClientSDK:CCM_SoftwareUpdatesManager"
    $SmsSoftwareUpdates.InstallUpdates([System.Management.ManagementObject[]] (Get-WmiObject -Query “SELECT * FROM CCM_SoftwareUpdate” -Namespace “ROOT\ccm\ClientSDK”)) | Out-Null
}
Catch [Exception] {
    If ($ContinueOnError -eq $true) {
        Write-Log "Trigger SCCM Install Updates failed: $($_.Exception.Message)"
    }
    Else {
        Throw "Trigger SCCM Install Updates failed: $($_.Exception.Message)"
    }
}
}