Author Posts

July 13, 2015 at 5:49 pm

I am trying to get a count of each software update group's expired updates and I am having a difficult time trying to get it done.

The ConfigurationManager module does not have a cmdlet that can do this for me so I am trying to create my own.

I did create the following script that does something similar to what I am looking for, but it uses a different WMI class and this is where I am having difficulty.

Here is the script that I created that works great for listing all the software update group names and also displays a total count of their respective software updates:

function Get-CMSoftwareUpdateCount
{
	Param (
		
		[string]$SMSProvider = $env:COMPUTERNAME,
		[string]$SiteCode
	)
	
	Try
	{
		$SUGProps = Get-WmiObject -Namespace "root\SMS\site_$($SiteCode)" -Class SMS_AuthorizationList -ComputerName $SMSProvider -ErrorAction 'Stop'
	}
	
	Catch
	{
		Throw "$Error"
	}
	
	Foreach ($SUG in $SUGProps)
	{
		$SMSAuthList = [wmi]"$($SUG.__PATH)"
		
		[pscustomobject] @{
			'SUGName' = $SUG.LocalizedDisplayName;
			'NumberofSUGUpdates' = $SMSAuthList.Updates.Count
		}
	}
}

Get-CMSoftwareUpdateCount -SMSProvider 'SCCM-PRI-01' -SiteCode 'PR1'

I am not certain how to get the pasted output formatted here, but the SUGName property displays on the left and the NumberOfSUGUpdates property displays on the right listing the count of all the updates in each software update group.

I want the same output, but I want it to list the total count of expired updates. In order to do this I have to use the "SMS_SoftwareUpdate" WMI class instead, but I am not certain how I can get the software update group names with it like in the script above.

Any help on this would be MUCH appreciated.

Thank you all for your help.

July 14, 2015 at 5:09 am

Looking at the WMI documentation for SMS_AuthorizedList, it indicates there is a property to identify expired items (IsExpired). You could try something like this:

function Get-CMSoftwareUpdateCount {
	Param (
    	[string]$SMSProvider = $env:COMPUTERNAME,
		[string]$SiteCode, #this should be made mandatory
        [switch]$ExpiredOnly
	)
	begin{}
    process{	    
        Try {
            $params = @{
                Class="SMS_AuthorizationList";
                Namespace="root\SMS\site_$($SiteCode)";
                ComputerName=$SMSProvider;
                ErrorAction='Stop';
            }

            if($ExpiredOnly){$params.Add("Filter", "IsExpired = 'True'")}

            $SUGProps = Get-WmiObject @params 
	    }	
	    Catch {
		    Throw "$Error"
	    }
	
	    Foreach ($SUG in $SUGProps) {
		    $SMSAuthList = [wmi]"$($SUG.__PATH)"
		
		    [pscustomobject] @{
			    'SUGName' = $SUG.LocalizedDisplayName;
			    'NumberofSUGUpdates' = $SMSAuthList.Updates.Count;
                'IsExpired' = $SUG.IsExpired;
		    }
	    } #foreach sug
    }
    end{}
}

Then you could sort by IsExpired or pass the -ExpiredOnly and return only expired updates. Total count would be something like:

$badUpdate += [pscustomobject] @{'SUGName' = "Group1";'NumberofSUGUpdates' = 22}
$badUpdate += [pscustomobject] @{'SUGName' = "Group2";'NumberofSUGUpdates' = 12}
$badUpdate += [pscustomobject] @{'SUGName' = "Group3";'NumberofSUGUpdates' = 3}

"Total:  {0}" -f ($badUpdate  | Measure-Object -Property NumberofSUGUpdates -Sum)

July 17, 2015 at 12:14 pm

Thanks Rob.

I'm having a hard time comprehending how I would use the second portion there.

If you don't mind, could you expound not hat a bit more, please?

Thank you for your help, I appreciate it big time.

July 20, 2015 at 3:46 am

The second portion was just an example. Your function is going to return a PSObject, so the example first creates a $badUpdate PSObject with 3 entries. Once we have the entries, you mentioned you would like the total number of badUpdates, so I was showing you how to use Measure-Object to get a total sum. The real code would be something like this:

$badUpdate = Get-CMSoftwareUpdateCount -ExpiredOnly -SiteCode "ABC"
"Total:  {0}" -f ($badUpdate  | Measure-Object -Property NumberofSUGUpdates -Sum)

July 23, 2015 at 6:25 pm

Oh gotcha!

Okay thanks