【发布时间】:2015-02-03 02:24:55
【问题描述】:
我想将远程 PowerShell 会话生成的错误传递回本地会话: (这工作)
Invoke-Command -Session $DevSession -ScriptBlock {sqlps -command E:\admin\DBA\Refresh_SQL_Config_Scripts.ps1 $args[0] $args[1]; $error} -args $SQLServer, $dbName -ErrorVariable +scriptDEVerror
问题:我想使用稍微调整的代码以易于阅读的格式获得它。我得到了标准结果,但 $error 显示为空白。 代码在这里:
Invoke-Command -Session $DevSession -ScriptBlock {sqlps -command E:\admin\DBA\Refresh_SQL_Config_Scripts.ps1 $args[0] $args[1]; $error.tostring() } -args $SQLServer, $dbName -ErrorVariable +scriptDEVerror
或者更好的是:
Invoke-Command -Session $DevSession -ScriptBlock {sqlps -command E:\admin\DBA\Refresh_SQL_Config_Scripts.ps1 $args[0] $args[1]; $error[0].tostring() } -args $SQLServer, $dbName -ErrorVariable +scriptDEVerror
有没有人知道如何让它工作?
【问题讨论】:
标签: powershell powershell-remoting