更新时间:2023-11-09 08:40:52
在您的情况下,我重申我之前关于-ExpandProperty
的声明.我仍然正确,因为它只会返回一个字符串数组而不是object属性.但是我认为,如果将其保留为对象,而只需添加要查找的属性"Computer",则将有更多选择.那就是我们可以将其作为一个不错的CSV了!我要假设这里有些循环结构没有显示出来.
In your case I recant my previous statement about -ExpandProperty
. I am still right in that it will return just a string array instead of the object property. However I think that you will have more options if you leave it as an object and just add the property "Computer" which you are looking for. That was we can just have it as a nice CSV! I am going to assume there is some loop structure here that you have not shown.
$list = Get-Content C:\Users\ajstepanik\Desktop\computers.txt
$list | ForEach-Object{
$computer = $_
Get-WmiObject -Class Win32_Product -ComputerName $computer |
Select-Object -Property Name |
Sort-Object Name |
Where-Object{$_.Name -match "Citrix"} |
Add-Member -MemberType NoteProperty -Name "Computer" -Value $computer -passthru
} | Export-Csv -NoTypeINformation -Path C:\temp\path.csv
因为我保留了对象,所以将select-string
更改为Where
n Match
.使用Add-Member
为Computer
添加属性.现在我们可以使用Export-CSV
Changed the select-string
to a Where
nMatch
since i kept the object. Used Add-Member
to add a property for Computer
. Now we can use Export-CSV
忘记了foreach($x in $y)
不能像其他foreach一样使用输出.
Forgot about foreach($x in $y)
doesnt work with output the way the other foreach does.