Passing parameters to powershell script in C#
hi, have read lot of posts regarding issue still can't make work
http://stackoverflow.com/questions/527513/execute-powershell-script-from-c-sharp-with-commandline-arguments
http://www.codeproject.com/articles/18229/how-to-run-powershell-scripts-from-c
http://social.msdn.microsoft.com/forums/en-sg/csharpgeneral/thread/faa70c95-6191-4f64-bb5a-5b67b8453237
i have windows form 2 textboxes
tb_user
tb_office
i have powershell script on c:\scripts\script.ps1 that need run 2 parameters
script.ps1 -user tb_user.tostring() -office tb_office.tostring()
so getting textbox content parameters call script on button click, code is:
 private void button1_click(object sender, eventargs e)          {              string user = tb_user.tostring();              string office = tb_office.tostring();              var scriptfile = @"c:\scripts\script.ps1";                  runspaceconfiguration runspaceconfiguration = runspaceconfiguration.create();                runspace runspace = runspacefactory.createrunspace(runspaceconfiguration);              runspace.open();                runspaceinvoke scriptinvoker = new runspaceinvoke(runspace);                pipeline pipeline = runspace.createpipeline();                //here's how add new script arguments              command mycommand = new command(scriptfile);              commandparameter userparam = new commandparameter("user", user);              mycommand.parameters.add(userparam);              commandparameter officeparam = new commandparameter("office", office);              mycommand.parameters.add(officeparam);                pipeline.commands.add(mycommand);                // execute powershell script              results = pipeline.invoke();            }      }  }  i got name results doesn't exist in current context, , also, nothing runs.. :(
can help?
thanks
refer link
http://www.codeproject.com/questions/213870/runnung-powershell-scripts-with-aruguments-using-c
and please refer this
http://blogs.msdn.com/b/zainnab/archive/2008/07/26/calling-a-powershell-script-from-your-net-code.aspx //this link give in detail in step step
tarun singh disclaimer: posting provided "as is" no warranties or guarantees , , confers no rights
                                                                          Visual Studio Languages                                                             ,                                                                 .NET Framework                                                     >                                                                 Visual C#                                                                            
 
 
Comments
Post a Comment