在Powershell中检查计算机是否已安装程序 [英] Check computers for installed program in powershell

查看:617
本文介绍了在Powershell中检查计算机是否已安装程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望能够在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

当前它输出:

@{Name=VMware Horizon View Client}
@{Name=VMware Horizon View Client}
@{Name=VMware Horizon View Client}

推荐答案

在您的情况下,我重申我之前关于-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-MemberComputer添加属性.现在我们可以使用Export-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

忘记了foreach($x in $y)不能像其他foreach一样使用输出.

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

这篇关于在Powershell中检查计算机是否已安装程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆