I was trying to run a powershell cmdlet on my C# application to get system information.
Collection <PSObject> a = PowerShell.Create().AddScript("Get-NetIPConfiguration -InterfaceAlias \"Беспроводная сеть 2\"").Invoke();
In response to my request, I receive a PSObject object. I was expecting to see data like object with parameters such as PS-commandLine that I can add to my own object. For example:
NetInterface n = new NetInterface();
n.name = a[0].InterfaceAllias;
n.ipv4 = a[0].IPv4Address;
But in reality, I have absolutely no idea how to get data from PSObject.
Of course, I can add | Out-String
to the command, and then parse the data as a string, however, I think there is a more elegant solution, How to get data in C# from powershell