Advertisement
Guest User

Untitled

a guest
Mar 28th, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.70 KB | None | 0 0
  1. ps.Commands.AddCommand("Get-Command");
  2.  
  3. InitialSessionState initial = InitialSessionState.CreateDefault();
  4. initial.ImportPSModule(new string[] {@"C:Program FilesMicrosoft Application VirtualizationClientAppvClientAppvClient.psd1" });
  5.  
  6. ps.Commands.AddCommand("Import-Module").AddArgument("AppvClient");
  7.  
  8. public static void powershellCommand()
  9. {
  10. Collection<PSObject> result;
  11.  
  12. using (Runspace myRunSpace = RunspaceFactory.CreateRunspace())
  13. {
  14. InitialSessionState initial = InitialSessionState.CreateDefault();
  15. initial.ImportPSModule(new string[] {@"C:Program FilesMicrosoft Application VirtualizationClientAppvClientAppvClient.psd1" });
  16. Runspace runspace = RunspaceFactory.CreateRunspace(initial);
  17. runspace.Open();
  18. PowerShell ps = PowerShell.Create();
  19. ps.Runspace = runspace;
  20. ps.Commands.AddCommand("Import-Module").AddArgument("AppvClient");
  21.  
  22. ps.Commands.AddCommand("Get-AppvVirtualProcess");
  23.  
  24. result = ps.Invoke();
  25. var builder = new StringBuilder();
  26. foreach (PSObject psObject in result)
  27. {
  28.  
  29. builder.Append(psObject.ToString() + "n");
  30. builder.ToString();
  31.  
  32. }
  33.  
  34. Console.WriteLine("Virtual Process: {0}", builder.ToString());
  35. }
  36.  
  37. }
  38.  
  39. public static void p()
  40. {
  41.  
  42. using (var powershell = PowerShell.Create())
  43. {
  44. powershell.AddCommand("Get-AppvVirtualProcess");
  45.  
  46. powershell.Invoke();
  47.  
  48. }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement