Is there any way to get powershell output in c# same way as it is when running command manually via powershell cmd? I.e. for example:
PS C:\temp> gci
Directory: C:\temp
Mode LastWriteTime Length Name
---- ------------- ------ ----
d---- 19.10.2018 9:57 SomeDir
-a--- 13.11.2018 17:03 3306 Somelog.log
And c# code:
PowerShell ps = PowerShell.Create();
ps.AddCommand("gci");
ICollection<PSObject> results = ps.Invoke();
foreach (PSObject invoke in results)
{
Console.WriteLine(invoke.ToString());
}
gives me:
SomeDir
Somelog.log