【问题标题】:I can't seem to capture warning output from a remote Invoke-command call我似乎无法从远程调用命令调用中捕获警告输出
【发布时间】:2015-10-19 11:32:59
【问题描述】:

以下SO问题似乎认为这是可能的:Powershell logging from invoke-command

最重要的答案(不是公认的答案),提到文档指出 Inovke-Command 返回所有内容,确实如此,强调我的。

https://technet.microsoft.com/en-us/library/hh849719.aspx

Invoke-Command cmdlet 在本地或远程计算机上运行命令 并返回命令的所有输出,包括错误

请注意,$PSVersionTable.PSVersion 输出 4.0 (Powershell ISE)。

这是有问题的代码

$out = Invoke-Command -Session $sess {
  Write-Warning 'w1'
}


'--'
$out
'--'

还有输出

WARNING: w1
--
--

我希望的是:

--
w1
--

意思是,我希望能够从警告流中捕获输出。

有什么解释吗?我该怎么做?

【问题讨论】:

  • 如果要将警告流重定向到输出,请使用3>&1

标签: powershell powershell-remoting


【解决方案1】:

使用Invoke-Command 的WarningAction 和WarningVariable 参数。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-08-19
    • 2014-01-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-12-01
    • 1970-01-01
    相关资源
    最近更新 更多