Click here to Skip to main content
15,892,965 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Am using the following code to Open PowerCli from C# and run commands on PowerCli through a button click.. after clicking the button in the debugger output am getting "The thread 0x104c has exited with code 259 (0x103)." which means my code was not succesfull . i dont know whats going wrong in my code can you please suggest me whats wrong am doing in my code?

Here is my code:

C#
private void Powercli_Click(object sender, EventArgs e)
        {
            RunspaceConfiguration config = RunspaceConfiguration.Create();
            Runspace runspace = RunspaceFactory.CreateRunspace(config);
            // open it
            runspace.Open();
            try
            {
                // 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 access = new Command("Connect-VIServer");
                access.Parameters.Add("Server", "192.168.123.108");
                access.Parameters.Add("Protocol", "https");
                access.Parameters.Add("User", "root");
                access.Parameters.Add("Password", "assign");
              // Add Command to Pipeline 
                pipeline.Commands.Add(access);
                //Execute by invoking
                pipeline.Invoke();
            }
            finally
            {
                runspace.Close();
            }
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900