【问题标题】:Powershell: Null Array Exception in passing args to Remote SessionPowershell:将参数传递给远程会话时出现空数组异常
【发布时间】:2017-03-27 22:49:21
【问题描述】:

我正在尝试在远程会话上运行命令,但我得到了一个

无法索引到空数组。 + CategoryInfo : InvalidOperation: (:) [], RuntimeException + 完全限定错误 ID:NullArray + PSComputerName : 服务器名称

我已经检查了我传递给远程会话的所有参数,它们都不是空的。以下是命令:

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 参数中传递的一些参数。

【问题讨论】:

  • 看来你打错了:$agrs[3] => $args[3]

标签: powershell invoke-command


【解决方案1】:

试试这个:

Invoke-Command -Session $session -ScriptBlock {
    Param($dir, $args, $outlog, $errlog)    
    Start-Process $dir -ArgumentList $args -RedirectStandardOutput $outlog -RedirectStandardError $errlog
} -ArgumentList $Consoledir,$arguments,$stdOutLog,$stdErrLog;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-11-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多