I'm trying to run Get-NetAdapter -Physical
from C#. If I run it from PS itself the resulting table has InterfaceDescription and MacAddress columns with meaningful values, however doing this in C#:
using (var ps = PowerShell.Create())
{
ps.AddCommand("Get-NetAdapter");
ps.AddParameter("Physical");
var results = ps.Invoke();
[...error checking here...]
foreach (var result in results)
{
[...null check here...]
var name = result.Members["InterfaceDescription"].Value;
var mac = result.Members["MacAddress"].Value;
}
}
The second line in the foreach throws a NullReferenceException at the left-hand side of .Value
. If I change Members
to Properties
the result is the same. name
is fine. I've also tried using dynamic
to get to the members but that doesn't seem to work either. How can I get to the object that I can obtain in PowerShell through thing.MacAddress
?