Select-Object, different output

Viewed 105

I am currently writing a script, that sends me an email, if a new Windows update gets released.

Get-WindowsUpdate

Output:

ComputerName Status     KB          Size Title                                                                                                                                               ------------ ------     --          ---- -----
MD-I-T-092   -------                 2MB Intel - System - 4/12/2017 12:00:00 AM - 14.28.47.630
MD-I-T-092   -------                24KB Dell Inc. - Monitor - 1/30/2018 12:00:00 AM - 
MD-I-T-092   -------                46KB Intel - System - 9/19/2017 12:00:00 AM - 11.7.0.1000
MD-I-T-092   -------                 9MB Lenovo Ltd. - Firmware - 1.0.0.50
MD-I-T-092   -------               346KB Lenovo Ltd. - Firmware - 1.0.0.41

At the moment, only "Driver" updates are available. When a Windows update is available, I want to retrieve the "KB" Number and the "Title" of the update.

Get-WindowsUpdate | Select-Object -Property KB (or Size/Title etc.)

This method doesent work.

Output

I guess that is because the Property is not available.

Get-WindowsUpdate | Select -Property *

All Properties

As this method (https://social.technet.microsoft.com/Forums/en-US/b7e3b522-04b5-4cd5-a228-837deff9d7b8/windows-update-powershell-module-display-category-with-getwindowsupdate-aka-getwulist-cmdlet?forum=ITCG) didnt work for me, do you have any other ideas on how to filter the output? On StackO I have not found an article that helped me, but if you know one, please let me know :)

2 Answers

I assume you are using the PsWindowsUpdate module. It seems that module is poorly written and doesn't emit nice useable objects by default.

You can get at them like this:

(Get-WindowsUpdate).GetEnumerator() | Where-Object KB -ne '' | Select-Object KB, Size, Title.

Which gives output like this (assuming matching updates are found):

KB        Size  Title
--        ----  -----
KB5011644 697MB SQL Server 2019 RTM Cumulative Update (CU) 16 KB5011644
KB5014356 457MB Security Update for SQL Server 2019 RTM GDR (KB5014356)
KB5013887 67MB  2022-06 Cumulative Update for .NET Framework 3.5 and 4.8 for Windows 10 Version 21H2 for x64 (KB5013887)
KB2267602 789MB Security Intelligence Update for Microsoft Defender Antivirus - KB2267602 (Version 1.367.1700.0)

The properties you're looking for aren't available because the Get-WindowsUpdate returns the collection of objects as a whole rather than streaming the elements one by one (like most cmdlets do). In which case, you would have been able to retrieve the individual properties from the objects.

Windows Update Collection

In order to get the information you're looking for, first pipe the Get-WindowsUpdate cmdlet to the ForEach-Object cmdlet and then select your properties from there.

Get-WindowsUpdate | ForEach-Object { $_ | Select Title, KB, Size }

Here's what I get with that:

Windows Update Properties

Related