我试图确定列表中的哪些服务器(例如servers.txt)安装了.NET 4.5以及PowerShell的版本。我有独立的命令,它会告诉我这在一个盒子 -为多个远程主机运行PowerShell命令并高效显示
**
**PS D:\tools> Get-ItemProperty 'HKLM:\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Client'
Version : 4.5.51641
CBS : 1
TargetVersion : 4.0.0
Install : 1
InstallPath : C:\Windows\Microsoft.NET\Framework64\v4.0.30319\
Servicing : 0
Release : 378675
PSPath : Microsoft.PowerShell.Core\Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework
Setup\NDP\v4\Client
PSParentPath : Microsoft.PowerShell.Core\Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4
PSChildName : Client
PSDrive : HKLM
PSProvider : Microsoft.PowerShell.Core\Registry**
** 这都说明在顶部(版),它的确是4.5。有没有办法以表格格式显示版本字段和主机名(或计算机名)?
此外,同为以下命令,向你的PowerShell的版本 -
PS D:\tools> get-host |select-object version
Version
-------
4.0
其实我放的完整路径。这是我的屏幕后,显示txt文件,然后运行命令 -
PS D:\tools> type h:\servers.txt
OPP-HOLD
zOPP-SQL12HAa
zOPP-SQLESMA
PS D:\tools> Get-content -path h:\servers.txt | where {$_-match "\S"} | foreach Get-ItemProperty -ComputerName $_ 'HKLM:
\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Client' -name Version
foreach : Input name "Get-ItemProperty" cannot be resolved to a method.
At line:1 char:60
+ Get-content -path h:\servers.txt | where {$_-match "\S"} | foreach Get-ItemPrope ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (OPP-HOLD:PSObject) [ForEach-Object], PSArgumentException
+ FullyQualifiedErrorId : MethodNotFound,Microsoft.PowerShell.Commands.ForEachObjectCommand
foreach : Input name "Get-ItemProperty" cannot be resolved to a method.
At line:1 char:60
+ Get-content -path h:\servers.txt | where {$_-match "\S"} | foreach Get-ItemPrope ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (zOPP-SQL12HAa:PSObject) [ForEach-Object], PSArgumentException
+ FullyQualifiedErrorId : MethodNotFound,Microsoft.PowerShell.Commands.ForEachObjectCommand
foreach : Input name "Get-ItemProperty" cannot be resolved to a method.
At line:1 char:60
+ Get-content -path h:\servers.txt | where {$_-match "\S"} | foreach Get-ItemPrope ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (zOPP-SQLESMA:PSObject) [ForEach-Object], PSArgumentException
+ FullyQualifiedErrorId : MethodNotFound,Microsoft.PowerShell.Commands.ForEachObjectCommand
'Invoke-Command'是正确的方法,但我认为OP正在寻找你没有的两个命令输出。此外,我不认为有一个PowerShell 4.5版本 – Matt 2014-10-02 16:42:29