Windows-我在使用/ f命令在Windows中选择特定列输出时遇到问题

问题描述 投票:0回答:1

我正在尝试获取Windows中安装的所有KB的列表。我使用以下命令。

C:\Windows>wmic qfe list
Caption                                     CSName        Description      FixComments  HotFixID   InstallDate  InstalledBy          InstalledOn  Name  ServicePackInEffect  Status
http://support.microsoft.com/?kbid=4514366  xxxx-LAP  Update                        KB4514366               NT AUTHORITY\SYSTEM  9/23/2019
http://support.microsoft.com/?kbid=4480056  xxxx-LAP  Update                        KB4480056               NT AUTHORITY\SYSTEM  8/6/2019
http://support.microsoft.com/?kbid=4512577  xxxx-LAP  Security Update               KB4512577               NT AUTHORITY\SYSTEM  9/23/2019
http://support.microsoft.com/?kbid=4512937  xxxx-LAP  Security Update               KB4512937               NT AUTHORITY\SYSTEM  9/13/2019
http://support.microsoft.com/?kbid=4516115  xxxx-LAP  Security Update               KB4516115               NT AUTHORITY\SYSTEM  9/23/2019
http://support.microsoft.com/?kbid=4521862  xxxx-LAP  Security Update               KB4521862               NT AUTHORITY\SYSTEM  10/20/2019
http://support.microsoft.com/?kbid=4519338  xxxx-LAP  Security Update               KB4519338               NT AUTHORITY\SYSTEM  10/20/2019

从上面的输出中,我仅对“ HotFixID”和“ InstalledOn”列输出感兴趣。我不需要其余的。

我正在使用以下命令,但是输出不正确,因为它不会忽略列的空间。

C:\Windows>for /f "tokens=5,8" %i in ('wmic qfe list ^| findstr /v "Caption"') do @echo HotFixID = %i, InstalledOn = %j
HotFixID = NT, InstalledOn =
HotFixID = NT, InstalledOn =
HotFixID = KB4512577, InstalledOn = 9/23/2019
HotFixID = KB4512937, InstalledOn = 9/13/2019
HotFixID = KB4516115, InstalledOn = 9/23/2019
HotFixID = KB4521862, InstalledOn = 10/20/2019
HotFixID = KB4519338, InstalledOn = 10/20/2019

我需要什么命令,该命令只能以上述格式提供“ HotFixID”和“ InstalledOn”的输出?

谢谢。

windows command-line patch windows-server
1个回答
0
投票

wmic可以自己过滤所需的数据。(第一个令牌始终为Node,因此我们取tokens=2,3)(标题被skip=2跳过)

这里的重要技巧是使用/format:csv来获取逗号作为分隔符(因此我们在不加任何空格的情况下进行标记化)

for /f "skip=2 tokens=2,3 delims=," %%a in ('wmic qfe get HotFixID^,InstalledOn /format:csv') do echo "HotFixID = %%a, InstalledOn = %%b
© www.soinside.com 2019 - 2024. All rights reserved.