2017-07-14 3 views
1

私はPowerShellを初めて導入しました。 私がしようとしているのは、名前付きパラメータを使用してリモートコンピュータ上の.exeを呼び出すことです。名前付きパラメータを使用したInvoke-Commandの開始プロセス

$arguments = "-clientId TX7283 -batch Batch82Y7" 
invoke-command -computername FRB-TER1 { Start-Process -FilePath "C:\Program Files (x86)\Acorne\LoadDen.exe" -ArgumemtList $arguments} 

このエラーが発生します。

A parameter cannot be found that matches parameter name 'ArgumemtList'. 
+ CategoryInfo: InvalidArgument: (:) [Start-Process], ParameterBindingException 
+ FullyQualifiedErrorId : NamedParameterNotFound, Microsoft.PowerShell.Commands.StartProcessCommand 
+ PSComputerName : FRB-TER1 

引数リストにはおそらくパラメータ名はありません。わからない。

答えて

1

これはあなたの仕事を行う必要があります。

$arguments = "-clientId TX7283 -batch Batch82Y7" 
invoke-command -computername FRB-TER1 {param($arguments) Start-Process -FilePath "C:\Program Files (x86)\Acorne\LoadDen.exe" -ArgumemtList $arguments} -ArgumentList $arguments 
+0

-ArgumentList $ argumentsが2回必要ですか?それでも、私には同じエラーが残っています。 – zorrinn

+0

追加のArgumentListを削除して試しました。今度は、 パラメータ 'ArgumentList'の引数を検証できません。引数がnullまたは空です。 – zorrinn

+0

@zorrinn:それ以上の追加はありません。最後のargリストは、invoke-commandのスクリプトブロック内に値を渡すためのものです。 Paramはブロック内でそれを受け入れるために使用されます。そして最後に、あなたが実際に渡したい場所の開始プロセスargリストに来るでしょう –

0

はこの1つを試してみてください:

# Lets store each cmd parameter in an array 
$arguments = @() 
$arguments += "-clientId TX7283" 
$arguments += "-batch Batch82Y7" 
invoke-command -computername FRB-TER1 { 
    param (
     [string[]] 
     $receivedArguments 
    ) 

    # Start-Process now receives an array with arguments 
    Start-Process -FilePath "C:\Program Files (x86)\Acorne\LoadDen.exe" -ArgumemtList $receivedArguments 
    } -ArgumentList @(,$arguments) # Ensure that PS passes $arguments as array 
0

あなたも(上ポッシュバージョン3.0から)$Using:Varnameを使用することができますリモートで実行スクリプトブロックにローカル変数を渡すには。 Invoke-Commandのヘルプを参照してください:

> help Invoke-Command -Full |Select-String -Pattern '\$using' -Context 1,7 

 PS C:\> Invoke-Command -ComputerName Server01 -ScriptBlock {Get-EventLog 
> -LogName $Using:MWFO_Log -Newest 10} 

    This example shows how to include the values of local variables in a 
    command run on a remote computer. The command uses the Using scope 
    modifier to identify a local variable in a remote command. By default, all 
    variables are assumed to be defined in the remote session. The Using scope 
    modifier was introduced in Windows PowerShell 3.0. For more information 
    about the Using scope modifier, see about_Remote_Variables 
  • scriptblocksが入れ子になっている場合は、$using:varnameだから、これは(未テスト)あまりにも動作するはずthis reference

を参照してください繰り返す必要があり

$arguments = "-clientId TX7283 -batch Batch82Y7" 
Invoke-Command -computername FRB-TER1 {Start-Process -FilePath "C:\Program Files (x86)\Acorne\LoadDen.exe" $Using:arguments} 
関連する問題