Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/windows/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Windows 检查是否使用powershell在远程服务器上安装了特定程序_Windows_Powershell_Scripting - Fatal编程技术网

Windows 检查是否使用powershell在远程服务器上安装了特定程序

Windows 检查是否使用powershell在远程服务器上安装了特定程序,windows,powershell,scripting,Windows,Powershell,Scripting,我正在编写一个脚本,需要检查是否在远程服务器上安装了特定的应用程序。我对PowerShell相当陌生,但下面是我编写的脚本 ForEach ($computers in $computer){ Get-WMIObject -Class win32_product -Filter {Name like "%Microsoft%"} -ComputerName $computers -ErrorAction STOP | Select-Object -Property Name,Versio

我正在编写一个脚本,需要检查是否在远程服务器上安装了特定的应用程序。我对PowerShell相当陌生,但下面是我编写的脚本

ForEach ($computers in $computer){
    Get-WMIObject -Class win32_product -Filter {Name like "%Microsoft%"} -ComputerName $computers -ErrorAction STOP | Select-Object -Property Name,Version | export-csv "C:\progrms.csv"
}
我在这里面临的问题是,我只能获得已安装的Microsoft应用程序的详细信息,如果我为过滤器参数提供多个名称,如“Microsoft”、“SQL”、“app1”等。这个脚本似乎不起作用


请让我知道哪里出了问题,需要做什么才能获得已安装的特定软件的列表。另外,请注意,我将在Windows 2008和2012服务器上使用此脚本

删除脚本的
-Filter{Name(如“%Microsoft%”)}
部分,使其返回所有已安装的软件

您可能希望执行
ForEach($computers in$computers)
,而不是相反,假设您正在使用计算机名称列表在此代码上方的某处创建一个
$computers
变量

您还需要将-附加“导出CSV”命令,否则每个计算机的输出都将覆盖上一个计算机的输出,然而,您将遇到的另一个问题是知道哪个软件来自哪个计算机。您可以通过使用计算属性将计算机名称添加到输出中来解决此问题,如下所示:

ForEach ($Computer in $Computers){
    Get-WMIObject -Class win32_product -ComputerName $Computer -ErrorAction Stop |
        Select-Object -Property @{N='Computer';E={$Computer}},Name,Version |
        Export-Csv "C:\progrms.csv" -Append
}

大多数人在问之前都会用谷歌搜索:你能解释一下你写的上面的脚本吗?你不明白什么部分?你给“属性”参数的值是多少@Mark Wragg
@{N='Computer';E={$Computer}
是一个计算属性,它向名为“Computer”的对象添加一个值为
$Computer
的属性。然后还返回现有的名称和版本属性。有关计算属性的更多信息,请参见此处:非常感谢!非常感谢你的帮助。但我还有另一个要求。我应该为它创建一个新的线程,还是可以在这里自己提问?