I am getting "PrincipalSource" property Blank while running following command by PowerShell Script in c#.
Command : Get-LocalGroupMember -Group Administrators
By C# Code passing Script path:
I have written output in text file.
Script is executing by c# Code because I can see output but PrincipalSource value blank.
System details:
Windows 10, PowerShell 5.1, .Net Version 4.8
Sample Code:
Runspace runspace = RunspaceFactory.CreateRunspace();
PowerShell powershell = PowerShell.Create();
powershell.Runspace = runspace
powershell.AddScript(scriptPath);
powershell.Runspace.Open();
powershell.Invoke();
powershell.Runspace.Close();
powershell.Dispose();
==========================================================
PowerShell powershell = PowerShell.Create();
powershell.AddCommand("Get-LocalGroupMember");
powershell.AddParameter("Name", "Administrators");
Collection <PSObject> results = powershell.Invoke(); ;
StringBuilder stringBuilder = new StringBuilder();
foreach (PSObject obj in results)
{
Console.WriteLine("{0,-20}{1}",
obj.Members["ObjectClass"].Value,
obj.Members["Name"].Value,
obj.Members["PrincipalSource"].Value);
}
Console.WriteLine("End");


