Home > Net >  Select-Object, different output
Select-Object, different output

Time:06-18

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.

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

CodePudding user response:

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)
  • Related