Powershell:向远程会话传递参数时出现空数组异常
我正试图在远程会话上运行命令,但收到一个错误消息 无法索引到空数组中。 +CategoryInfo:InvalidOperation:(:)[],运行时异常 +FullyQualifiedErrorId:NullArray +PSComputerName:serverName 我已经检查了传递给远程会话的所有参数,没有一个是空的。命令如下:Powershell:向远程会话传递参数时出现空数组异常,powershell,invoke-command,Powershell,Invoke Command,我正试图在远程会话上运行命令,但收到一个错误消息 无法索引到空数组中。 +CategoryInfo:InvalidOperation:(:)[],运行时异常 +FullyQualifiedErrorId:NullArray +PSComputerName:serverName 我已经检查了传递给远程会话的所有参数,没有一个是空的。命令如下: Invoke-Command -Session $session -ScriptBlock {Start-Process $args[0] -Argumen
Invoke-Command -Session $session -ScriptBlock {Start-Process $args[0] -ArgumentList $args[1] -RedirectStandardOutput $args[2] -RedirectStandardError $agrs[3]} -Args $Consoledir,$arguments,$stdOutLog,$stdErrLog;
我使用此命令运行在$dir参数(D:\Temp\console.exe)中传递的控制台应用程序。此应用程序进一步接受在$arguments参数中传递的一些参数。请尝试以下操作:
Invoke-Command -Session $session -ScriptBlock {
Param($dir, $args, $outlog, $errlog)
Start-Process $dir -ArgumentList $args -RedirectStandardOutput $outlog -RedirectStandardError $errlog
} -ArgumentList $Consoledir,$arguments,$stdOutLog,$stdErrLog;
试试这个:
Invoke-Command -Session $session -ScriptBlock {
Param($dir, $args, $outlog, $errlog)
Start-Process $dir -ArgumentList $args -RedirectStandardOutput $outlog -RedirectStandardError $errlog
} -ArgumentList $Consoledir,$arguments,$stdOutLog,$stdErrLog;
看起来您有输入错误:
$agrs[3]
=>$args[3]
看起来您有输入错误:$agrs[3]
=>$args[3]