Hi All,
I have a c# code segment which process a power-shell script. The following is the code segment.
Runspace objRunspace = null; objRunspace = RunspaceFactory.CreateRunspace(); objRunspace.Open(); PowerShell powershell = PowerShell.Create(); powershell.Runspace = objRunspace; powershell.AddScript("my powershell script"); Collection<PSObject> objPS1 = powershell.Invoke(); if (objPS1.Count == 0) { //I Assumes that the PC is down }
In this case, If the login credentials are wrong or if that particular PC is not available; the ObjPS1.count will be zero. If that count is Zero, I assumes that the host is unavailable. But in accuracy point of view, I want to identify both these (wrong credentials / host unavailable) situations separate. Is there a better way or different approach to achieve the same.
Thanks in advance
Sebastian