End Google Ads 201810 - BS.net 01 --> I am having a problem being able to run commandlets that are in modules from C#.

when I Invoke the import-module command via ps.AddScript or ps.Addcommand I do not get an error thrown on the second Invoke.

can anyone help me figure out what I am doing wrong.

PowerShell ps;
ps = PowerShell.Create();
ps.AddScript(@"import-module GroupPolicy");
ps.Invoke();
ps.AddCommand("Get-GPO");
try { ps.Invoke(); }
catch (RuntimeException runtimeException)
{
System.Console.WriteLine("Runtime exception: {0}: {1}\n{2}",
runtimeException.ErrorRecord.InvocationInfo.InvocationName,
runtimeException.Message,
runtimeException.ErrorRecord.InvocationInfo.PositionMessage);
}