windows - 选择对象,不同的输出

标签 windows powershell select get output

我目前正在编写一个脚本,如果发布新的 Windows 更新,它会向我发送一封电子邮件。

获取 WindowsUpdate

输出:

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

目前,仅提供“驱动程序”更新。当 Windows 更新可用时,我想检索更新的“KB”号和“标题”。

获取 WindowsUpdate |选择对象-属性KB(或大小/标题等)

这个方法不起作用。

Output

我猜这是因为该属性不可用。

获取 WindowsUpdate |选择-属性*

All Properties

由于此方法( 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 )对我不起作用,您对如何过滤输出还有其他想法吗? 在 StackO 上我没有找到一篇对我有帮助的文章,但如果你知道,请告诉我:)

最佳答案

我假设您正在使用 PsWindowsUpdate模块。 看来该模块编写得不好,并且默认情况下不会发出很好的可用对象。

你可以这样获取它们:

(Get-WindowsUpdate).GetEnumerator() |哪里对象 KB -ne '' |选择对象KB、大小、标题

它给出这样的输出(假设找到匹配的更新):

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)

关于windows - 选择对象,不同的输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72657554/

相关文章:

windows - 在 PowerShell 中递归地将一组文件从一个目录复制到另一个目录

windows - WIndows 7 上的高频数据监听器 TCP 过载

c++ - Qt 4.7.3 中缺少 Qtcreator.exe

regex - Powershell获取内容忽略换行符

xml - 如何使用 ConvertTo-Xml 和 Select-Xml 加载或读取 XML 文件?

sql - SQL —在SELECT中创建列以测试是否相等

windows - 无需额外的外部软件即可将 .bat 转换为 .exe(创建 SFX)

powershell - 错误: "Select-AzureSubscription Must specify a non-null subscription name"

jquery - 如何验证jquery中的选择字段?

jquery - 如何获取下拉列表中选定值的文本?