I am working on a function that will get the number of expired updates in a software update group, but I am missing something here. If there are no expired updates, I want it to simply output each software update group name under the SoftwareUpdateGroup property along with false under the ExpiredSoftwareUpdates property. It is producing multiple duplicates of software update group names under the SoftwareUpdateGroup property and I am not certain how to control this. I feel like I am forgetting something fundamental here, but I cannot recall what it is.
Here is the code:
Function Count-CMExpiredSoftwareUpdates { Param ( [string]$SiteServer = $env:COMPUTERNAME, [string]$SiteCode ) $AllSUGS = Get-WmiObject -Namespace "root\SMS\site_$($SiteCode)" -Class SMS_AuthorizationList -ComputerName $SiteServer -ErrorAction Stop Foreach ($SUG in $AllSUGS) { $SMSAuthList = [wmi]"$($SUG.__PATH)" Foreach ($SoftwareUpdate in $SMSAuthList.Updates) { $CIID = Get-WmiObject -Namespace "root\SMS\site_$($SiteCode)" -Class SMS_SoftwareUpdate -ComputerName $SiteServer -Filter "CI_ID = '$($SoftwareUpdate)'" -ErrorAction Stop If ($SoftwareUpdate.IsExpired -eq $true) { [pscustomobject] @{ 'SoftwareUpdatesGroup' = $SUG.LocalizedDisplayName; 'ExpiredSoftwareUpdatesCount' = $CIID.IsExpired.Count } } Else { [pscustomobject] @{ 'SoftwareUpdatesGroup' = $SUG.LocalizedDisplayName; 'ExpiredSoftwareUpdatesCount' = $false } } } } } Count-CMExpiredSoftwareUpdates -SiteCode 'PRI'