"New-PSSession" Cmdlet in Windows PowerShell

Q

How to use "New-PSSession" cmdlet in Windows PowerShell?

✍: FYIcenter.com

A

You can use the "New-PSSession" cmdlet to create a PSSession on a remote computer.

The New-PSSession cmdlet creates a Windows PowerShell session (PSSession) on one or more remote computers.

Once a PSSession is created on a remote computer, it will live on the remote computer independently from your local computer. And you are allowed to do the following:

  • Keep the PSSession connected to your local computer.
  • Send commands to the PSSesion from your local computer with "Invoke-Commands" cmdlet.
  • Disconnect the PSSession from your local computer with "Disconnect-PSSession" cmdlet.
  • Reconnect the PSSession from your local computer (or another computer) with "Connect-PSSession" cmdlet or "Enter-PSSession" cmdlet for older versions of PowerShell.
  • Terminate the PSSession from your local computer (or another computer) with "Remove-PSSession" cmdlet.

Here are example commands to create PSSessions on remote computers:

PS C:\fyicenter> # Create a PSSession on "office-server" computer
PS C:\fyicenter> new-pssession office-server

PS C:\fyicenter> # Create an another PSSession on "office-server" computer
PS C:\fyicenter> # And save the PSSession object in variable $s
PS C:\fyicenter> $s = new-pssession office-server

PS C:\fyicenter> # Create multiple PSSessions on multiple computers
PS C:\fyicenter> new-pssession office-server,hr-server,it-server

 

Managing Remote Computer with Windows PowerShell

⇒⇒Windows PowerShell Tutorials

2016-10-17, 371👍, 0💬