when I try to use the PowerShell cmdlet "Get-LocalGroup" in my c# application it won't print out any output of this cmdlet on my console.
I've already included the Management.Automation NuGet. The build process works without problems. I also tried to start the built .exe with admin permissions in debug and release mode.
using System.Collections.ObjectModel;
using System.Management.Automation;
namespace RunPowershell
{
class Program
{
static void Main(string[] args)
{
using (PowerShell PowerShellInstance = PowerShell.Create())
{
PowerShellInstance.AddScript("Get-LocalGroup");
Collection<PSObject> PSOutput = PowerShellInstance.Invoke();
// loop through each output object item
foreach (PSObject outputItem in PSOutput)
{
if (outputItem != null)
{
System.Console.WriteLine("-"+outputItem.BaseObject);
}
}
System.Console.WriteLine("Hit any key to exit.");
System.Console.ReadKey();
}
}
}
}
I can't see a significant error in the debug window, but there's also no output of "Get-LocalGroup".