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 #57 Import-PSSession

    Posted on February 5th, 2010 Jonathan Medd No comments

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

    What can I do with it?

    Import commands from a Remote PowerShell session into the current session, for instance from a remote session on another computer.

    Example:

    Establish a remote session with Test01 using New-PSSession. Use Invoke-Command to initiate the use of the BITSTransfer module. Use Import-PSSession to make the contents of the BITSTransfer module available in the local session even though the BITSTransfer module has not been imported on the local computer.

    Note: Technically I could just have imported the BITSTransfer module on the local machine, however this example is to demonstrate that potentially any module could be brought across to the local session.

    $session1 = New-PSSession -ComputerName Test01
    Invoke-Command -Session $session1 -ScriptBlock {Import-Module BITSTransfer}
    Import-PSSession -Session $session1 -Module BITSTransfer

    Import-PSSession1

    Confirm the contents of the BITSTransfer module is now available in the local session.

    Get-Command *Bits* -CommandType Function

    Import-PSSession2

    Extras:

    Ravikanth Chaganti has an excellent post covering this cmdlet in more detail here.

    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