Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Powershell:向远程会话传递参数时出现空数组异常_Powershell_Invoke Command - Fatal编程技术网

Powershell:向远程会话传递参数时出现空数组异常

Powershell:向远程会话传递参数时出现空数组异常,powershell,invoke-command,Powershell,Invoke Command,我正试图在远程会话上运行命令,但收到一个错误消息 无法索引到空数组中。 +CategoryInfo:InvalidOperation:(:)[],运行时异常 +FullyQualifiedErrorId:NullArray +PSComputerName:serverName 我已经检查了传递给远程会话的所有参数,没有一个是空的。命令如下: Invoke-Command -Session $session -ScriptBlock {Start-Process $args[0] -Argumen

我正试图在远程会话上运行命令,但收到一个错误消息

无法索引到空数组中。 +CategoryInfo:InvalidOperation:(:)[],运行时异常 +FullyQualifiedErrorId:NullArray +PSComputerName:serverName

我已经检查了传递给远程会话的所有参数,没有一个是空的。命令如下:

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]