我試圖確定列表中的哪些服務器(例如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