Hi,
I have this code that starts Windows PowerShell. It fails since Windows PS doesn't have the Connect-VIServer command.
How can I start the VI Toolkit instead or on top of Windows PS.
Runspace runspace = RunspaceFactory.CreateRunspace();
runspace.Open();
Pipeline pipeline = runspace.CreatePipeline();
pipeline.Commands.AddScript("Connect-VIServer -Server " + vcserver);
Collection results = pipeline.Invoke();
runspace.Close();
Thanks,
Yaniv
I've only played with the toolkit briefly so far, but ran into some trouble getting things to start correctly until I added the following line to the beginning of my powershell scripts:
Add-PSSnapin VMware.VimAutomation.Core
After that I could call the connect-VIserver function. I'm not sure how this plays into your use of C# with powershell, but hopefully it may give you some other ideas to try.
I hope this helps to some degree.
The way I usually get around this is to use a PowerShell profile to load all of the snap-ins I want without having to re-type the commands every time I open PowerShell.
There are various locations for the profile, based on who the profile is for (either user or system wide). Do a quick google search on PowerShell profiles and you will get lots of information.
I managed to solve this one -
I've created a configuration that includes the PS snap in:
// create PS runspace config.
RunspaceConfiguration config = RunspaceConfiguration.Create();
PSSnapInException snapInException = null;
config.AddPSSnapIn("VMware.VimAutomation.Core", out snapInException);
I get other error but I'll open a new thread.
Thank you,
Yaniv
Please rate helpful / correct answers. Thank you
Hi there. Were you ever able to get config.AddPSSnapIn("VMware.VimAutomation.Core", out snapInException) working in your C# asp page? I am running into the same issue. Thanks!
Tim