PowerShell 2.0: One Cmdlet at a Time 57 Import-PSSession
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
Confirm the contents of the BITSTransfer module is now available in the local session.
Get-Command *Bits* -CommandType Function
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.