![](/img/trans.png)
[英]How to get Invoke-Command verbose or debug output from a PowerShell command in C#
[英]Powershell Invoke invalid command output C#
To get the errors, you can check if the powershell object HadError then look into Streams.Error property of the powershell object and for each ErrorRecord , you can get the Exception, StackTrace, ToString, etc:
using (var powerShell = PowerShell.Create())
{
var output = powerShell.AddScript("abc").Invoke();
if(powerShell.HadErrors)
{
foreach(var error in powerShell.Streams.Error)
{
Console.WriteLine(error.ToString());
}
}
}
注意: PowerShell 為不同目的提供多個流:調試、錯誤、信息、進度、詳細、警告。 您可以使用 powershell 實例的Streams屬性獲取流。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.