I have the following PS Script(built with the PowerShell C# object):
List<string> powershellResults = new List<string>();
foreach (string str in PowerShell.Create().AddScript("Get-ADGroupMember \"Domain Users\" -Server \"Server\" | Select-Object -Property \"Name\" | Format-List").AddCommand("Out-String").Invoke<String>())
{
powershellResults.Add(str);
}
However, I quickly found that instead of looping through the returned PS list, it just sticks the entire output of the PS List into the C# container(so there is only 1 entry that looks like:
Name : Alf
Name : Jim
Name : Carrol
How can I get PS to return each result individually? Or will I have to do some string manipulation in C# on the PS output?
Out-Stringoutputs a string, not a string array what i think you are expecting