Scripting. Powershell, VMware, Windows, Active Directory & Exchange. All that kind of stuff…..
RSS icon Email icon Home icon
  • PowerShell 2.0: One Cmdlet at a Time #33 New-PSSession

    Posted on January 8th, 2010 Jonathan Medd No comments

    Continuing the series looking at new cmdlets available in PowerShell 2.0. This time we look at the New-PSSession cmdlet.

    What can I do with it?

    Establish a persistent connection to a computer that has been enabled for PowerShell remoting.

    Examples:

    Establish a persistent remote PowerShell connection to Test01 and store it in the variable $session. Then use the Enter-PSSession cmdlet with the Session parameter to use that session.

    $session = New-PSSession -ComputerName Test01
    Enter-PSSession -Session $session

    You can also open multiple sessions via different methods:

    Open sessions to Test01, Test02 and Test 03.

    $session1, $session2, $session3 =
     New-PSSession -ComputerName Test01,Test02,Test03

    Or if you have the servers stored in a csv file.

    $sessions = New-PSSession -ComputerName (Get-Content servers.csv)

    How could I have done this in PowerShell 1.0?

    Remoting did not exist in PowerShell 1.0, you would have needed to use Remote Desktop to run an interactive session on a remote server.

    1000 things 1% better!

    Leave a reply