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:
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.
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:
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: