在多台计算机上获取修补程序并导出到 CSV [英] Get-hotfix on multiple computers and exporting to CSV
本文介绍了在多台计算机上获取修补程序并导出到 CSV的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在输出文件中正确使用 $_?这是我的代码:
How do I properly use $_ in out-file? Here's my code:
get-content computers.txt |
Where {$_ -AND (Test-Connection $_ -Quiet)} |
foreach { Get-Hotfix -computername $_ } |
Select CSName,Description,HotFixID,InstalledBy,InstalledOn |
convertto-csv | out-file "C:\$_.csv"
我正在尝试为文本文件中列出的所有计算机执行 get-hotfix,然后我希望它们以计算机名称作为文件名导出到 CSV.
I'm trying to execute a get-hotfix for all the computers listed in the text file then I want them to be exported to CSV with the computer name as the filename.
推荐答案
您需要一个管道来处理 computer.txt 文件,以及一个嵌套在 foreach
中的管道来处理每台计算机:
You need one pipeline to process the computers.txt files, and a nested one inside the foreach
to process the list of hotfixes for each computer:
get-content .\computers.txt |
Where {$_ -AND (Test-Connection $_ -Quiet)} |
foreach {
Get-Hotfix -computername $_ |
Select CSName,Description,HotFixID,InstalledBy,InstalledOn |
convertto-csv | out-file "C:\$_.csv"
}
将 computers.txt
更改为 .\computers.txt
,因为这是 powershell 中的本地路径所必需的
Changed computers.txt
to .\computers.txt
, as this is required for local paths in powershell
这篇关于在多台计算机上获取修补程序并导出到 CSV的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文