Powershell Export-CSV issues

我们两清 提交于 2019-12-12 05:48:31

问题


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
    }

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?

Thanks in advance for the help.


回答1:


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
}


来源:https://stackoverflow.com/questions/42233416/powershell-export-csv-issues

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!