Powershell导出CSV问题 [英] Powershell Export-CSV issues
问题描述
我目前拥有以下脚本,该脚本非常适合从远程计算机列表中收集已安装程序的列表.
I currently have the following script that works well for gathering a list of installed programs from a list of remote computers.
$PCListOld = Get-Content F:\PCList-Old.txt
ForEach ($PC in $PCListOld)
{
$AppList = Get-WmiObject -Computer $PC Win32_Product | Sort-Object Name
$AppList | Export-CSV C:\~Scripts\AppLists\$PC.csv
}
但是,我实际上只需要$ AppList中的Name属性,但是如果我只是将$ AppList.Name用管道传输到Export-CSV,则在csv中不会得到与在屏幕上相同的输出.有人可以给我一些有关如何编辑它的建议,以便我可以将Name值导出到csv文件吗?
However, I really only need the Name property in $AppList, but if I simply pipe $AppList.Name to Export-CSV, I don't get the same output in the csv as I would have on the screen. Can someone give me some advice on how I should edit this so I can just get the Name value exported to the csv file?
预先感谢您的帮助.
推荐答案
通过Select-Object
将结果属性限制为Name
:
Restrict the result properties to just Name
via Select-Object
:
foreach ($PC in $PCListOld) {
Get-WmiObject -Computer $PC Win32_Product |
Sort-Object Name |
Select-Object Name |
Export-Csv C:\~Scripts\AppLists\$PC.csv
}
这篇关于Powershell导出CSV问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!