Guest User

Untitled

a guest
Aug 21st, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. Calling New-PSSession from ASP.NET app fails (creates null object)
  2. param($serverName, $rootPath, $appsToInstall)
  3. $session = Enter-PsSession -ComputerName $serverName
  4.  
  5. $command = {
  6. param($path,$apps)
  7. $pathtempIISsetup.ps1 $path $apps
  8. }
  9.  
  10. $output = Invoke-Command -Session $session -scriptblock $command -ArgumentList
  11. $rootPath,$appsToInstall
  12.  
  13. Remove-PSSession -Session $session
  14.  
  15. using (Runspace remoteRunspace = RunspaceFactory.CreateRunspace())
  16. {
  17. remoteRunspace.Open();
  18. using (PowerShell ps = PowerShell.Create())
  19. {
  20. ps.Runspace = remoteRunspace;
  21.  
  22. var cmd = new Command(Path.Combine(ServerPath, "LocalIISSetupLauncher.ps1"));
  23. cmd.Parameters.Add("serverName", this.Server.ServerName);
  24. cmd.Parameters.Add("rootPath", LocalIisDirectory);
  25. cmd.Parameters.Add("appsToInstall", Server.InstalledApplications.ToList().ToArray());
  26.  
  27. ps.Commands.AddCommand(cmd);
  28.  
  29. var results = ps.Invoke();
Add Comment
Please, Sign In to add comment