2017-05-31 9 views
0

ドメイン内のサーバーから情報を確認したいことがあります。この例では、私はリモートで(現在はループせずにただ一つのサーバ、)Windowsのバージョンを取得しようとしています:Powershell:Get-WmiObjectはループ内でJobとして実行できません

$cr=Get-Credential "domain\adm_user" 
$computer="serverA" 
Invoke-Command { Get-WmiObject -Class Win32_OperatingSystem -Namespace root/cimv2 -Computer $computer -Credential $cr | Format-List -Property Name, OSArchitecture, SerialNumber} -AsJob -ComputerName . 
Get-Job | Wait-Job 
Get-Job | Receive-Job 

出力:

Cannot validate argument on parameter 'ComputerName'. The argument is null or empty. Supply an argument that is not null or empty and then try the command again. 

ようだ、そのスクリプトブロックは{}変数$computerを見ることはできません。 変数-computer $computerをサーバの名前に置き換えると、動作しています。 Invoke-Commandコマンド内部変数の展開については

+0

正しいパラメータは '-ComputerName'です - あなたは-Computerを使用していますか? – Jelphy

+0

ComputerとComputerNameはエイリアスです。私は長い名前を試して、出力(エラー)は同じです。 – Jerry1

答えて

1

はPARAMブロックを使用して引数を指定します。

$computer = 'localhost' 
Invoke-Command {param($computer) Get-WmiObject Win32_OperatingSystem -Computername $computer } -ArgumentList $computer 

は、PS V5に取り組みます。

関連する問題