I have a Powershell Script that is stored in a line called "script" with the contents:
get-user | out-file C:\Users\user\Desktop\user.txt -append
My C # code:
RunspaceConfiguration runConfig = RunspaceConfiguration.Create(); PSSnapInException psEx = null; runConfig.AddPSSnapIn("VMWare.View.Broker", out psEx); Runspace runspace = RunspaceFactory.CreateRunspace(runConfig); runspace.Open(); Pipeline pipeline = runspace.CreatePipeline(); pipeline.Commands.AddScript(script); Collection<PSObject> results = new Collection<PSObject>(); results = pipeline.Invoke(); runspace.Close();
If I debug the code, I get the following exception:
No snap-ins have been registered for Windows Powershell Version 2
If I run Script manually and add a snap, it works fine
source share