Hi All,
PowerShell.Streams.Warning is not being capture.
I'm using powershell version 3.0.
I used the below code to capture warning & errors, error works well , but not warning.
It seems I'm missing something in the code to capture the warning.
Please help me to correct the code to capture warning also.
PowerShell powershell = PowerShell.Create();
powershell.Runspace = CreateRunSpace.runspace;
var exec = "Set-Mailbox -Identity John -DeliverToMailboxAndForward $true -ForwardingSMTPAddress'manuel@contoso.com'";
powershell.AddScript(exec);
powershell.Streams.Error.Clear();
powershell.Streams.Warning.Clear();
var result = powershell.Invoke();
MessageBox.Show(powershell.Streams.Error.Count().ToString()+" error counts");
foreach (var errorRecord in powershell.Streams.Error)
{
MessageBox.Show(errorRecord.ToString()+"first - error");
}
MessageBox.Show(powershell.Streams.Warning.Count().ToString() + " Warning counts");
foreach (var Warningc in powershell.Streams.Warning)
{
MessageBox.Show(Warningc.ToString() + "first - Warningc");
}
Thank you in advance