我们正在检测是否已安装citrix,在Powershell中检查计算机是否已安装程序

I want to be able to look for an installed program in powershell and output to a file the results. So far, I have something that will list the install programs, and select the string that has the name of the program, but I am not sure how to specify a text file for it to use for the list of systems, and a way to make it output cleanly.

Get-WmiObject -Class Win32_Product -cn $computernamehere | Select-Object -Property Name | Sort-Object Name | Select-String Vmware | Out-File C:\Users\ajstepanik\Desktop\installed_programs.txt

I would like it to output in a fashion like:

COMPUTER1 - VMware Horizon View Client

COMPUTER2 - VMware Horizon View Client

COMPUTER3 - VMware Horizon View Client

Currently it outputs:

@{Name=VMware Horizon View Client}

@{Name=VMware Horizon View Client}

@{Name=VMware Horizon View Client}

解决方案

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

Changed the select-string to a WherenMatch since i kept the object. Used Add-Member to add a property for Computer. Now we can use Export-CSV

Forgot about foreach($x in $y) doesnt work with output the way the other foreach does.

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值