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

Windows - I have an issue in selecting specfic column outputs using for /f command in windows

我正在尝试获取 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" 列输出感兴趣。我不需要其余的。

我正在使用以下命令,但输出不正确,因为它没有忽略列的 space。

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" 的输出?

谢谢。

wmic 可以自行过滤所需的数据。
(第一个标记总是 Node,因此我们取 tokens=2,3
(Header 被跳过 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