Server-2 から Server-1 (つまり、リモート サーバー) に対して次の PowerShell スクリプトを実行しようとしています。
$DBServer = 'Server1'
Invoke-Command -ComputerName $DBServer -ScriptBlock {
$status = Start-Process "C:\Program Files\iQ4bis\HaloSource\HaloSource.Run.exe" '"D:\Test\UsageTracking.iqp" /wf "Default Workflow" /e "Dev" ' -Wait -PassThru
$test2 = $status.ExitCode
if ($test2 -ne 0)
{
Throw "The command exited with error code: $test2"
}
else
{
Write-host "Workflow executed successfully."
}
}
質問: コード部分
"C:\Program Files\iQ4bis\HaloSource\HaloSource.Run.exe" '"D:\Test\UsageTracking.iqp" /wf "Default Workflow" /e "Dev" ' -Wait -PassThru
D:\Test\UsageTracking.iqp
との値Dev
はプロジェクトごとに変化するため、パラメータ化したかったのです。パラメータを使用して新しい値を渡すにはどうすればよいですか? 可能であれば、これが私が望んでいた方法です:
clear-host
$DBServer = 'Server1'
$v1 = 'D:\Test\UsageTracking.iqp'
$v2 = 'Dev'
$v3 = "C:\Program Files\iQ4bis\HaloSource\HaloSource.Run.exe"
Invoke-Command -ComputerName $DBServer -ScriptBlock {
param(
[string] $IQPFileDestinationLocation = $v1, [string] $ExecutionEnvironment = $v2, [string] $exe = $v3
)
$IQPFileLocation = $IQPFileDestinationLocation
$workflow = "Default Workflow"
$environment = $ExecutionEnvironment
$test = """$exe"" '""$IQPFileLocation"" /wf ""$workflow"" /e ""$environment""'"
$test
$status = Start-Process $test -Wait -PassThru
$test2 = $status.ExitCode
if ($test2 -ne 0)
{
Throw "The command exited with error code: $test2"
}
else
{
Write-host "It went ok."
}
} -ArgumentList $v1 ,$v2 ,$v3
上記を実行すると、次のエラー メッセージが表示されます。
This command cannot be run due to the error: The system cannot find the file specified.
+ CategoryInfo : InvalidOperation: (:) [Start-Process], InvalidOperationException
+ FullyQualifiedErrorId : InvalidOperationException,Microsoft.PowerShell.Commands.StartProcessCommand
+ PSComputerName : ken-dev-bi001
The command exited with error code:
At line:8 char:1
+ Invoke-Command -ComputerName $DBServer -ScriptBlock {
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : OperationStopped: (The command exited with error code: :String) [], RuntimeException
+ FullyQualifiedErrorId : The command exited with error code:
それを機能させるために、どんな助けも感謝します。