pipeline.Invoke();
private void Powercli_Click(object sender, EventArgs e) { RunspaceConfiguration config = RunspaceConfiguration.Create(); Runspace runspace = RunspaceFactory.CreateRunspace(config); // open it runspace.Open(); try { RunspaceInvoke scriptinvoker = new RunspaceInvoke(runspace); // import PowerCLI ViCore snapin PSSnapInException warning; config.AddPSSnapIn("VMware.VimAutomation.Core", out warning); if (warning != null) { throw warning; } // create a pipeline and feed it the script text Pipeline pipeline = runspace.CreatePipeline(); // Create Command to Set Na Option var connectVI = new Command("Connect-VIServer"); connectVI.Parameters.Add("Server", "192.168.123.108"); connectVI.Parameters.Add("Protocol", "https"); connectVI.Parameters.Add("User", "root"); connectVI.Parameters.Add("Password", "assign"); Command mycommand = new Command("C:\\script\\resource.ps1"); // Add Command to Pipeline pipeline.Commands.Add(connectVI); pipeline.Commands.Add(mycommand); //pipeline.Commands.Add(mycommand1); //Execute by invoking pipeline.Invoke(); if (pipeline.HadErrors) { MessageBox.Show(pipeline.Error.ToString(), "Error occurred"); } } finally { runspace.Close(); } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)