Advertisement
Guest User

Untitled

a guest
Feb 21st, 2019
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. var rs = RunspaceFactory.CreateRunspace();
  2. rs.Open();
  3.  
  4. // create a pipeline to add the variable into the runspace
  5. var pipeline = PowerShell.Create();
  6. // create a command object, add commands and parameters to it...
  7. var cmd = new PSCommand();
  8. cmd.AddCommand("New-Variable");
  9. cmd.AddParameter("Name", "foo");
  10. cmd.AddParameter("Value", "@()");
  11. // associate the command with the pipeline and runspace, and then invoke
  12. pipeline.Commands = cmd;
  13. pipeline.Runspace = rs;
  14. pipeline.Invoke();
  15.  
  16. cmd.AddParameter("Value", new object[0]);
  17.  
  18. pipeline.Runspace.SessionStateProxy.PSVariable.Set("foo", new object[0]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement