堆,
你如何区分 PSObjects 是由 WriteObject() WriteWarning() WriteError() 创建的?
从此开始:
psCmd = PowerShell.Create();
Runspace = RunspaceFactory.CreateRunspace();
Runspace.Open();
psCmd.Runspace = Runspace;
psCmd.AddCommand(cmdletName);
Collection<PSObject> results = null;
results = psCmd.Invoke();
该results
变量包含从命令行输出的所有 PSObject。您如何通过命令行开关识别由 WriteObject() WriteError() WriteWarning() 创建的 PSObject?
我想添加实现以下目标的代码:
foreach(psObj in results) {
if ( IsWarning(psObj) )
{
// Turn on yellow flashing lights
}
else if ( IsError(psObj) )
{
// Turn on red flashing lights
}
else
{
// Write to ticker-tape
}
}