PowerShell 2.0: One Cmdlet at a Time 58 Export-PSSession
Continuing the series looking at new cmdlets available in PowerShell 2.0. This time we look at the Export-PSSession cmdlet.
What can I do with it?
Export commands from a remote PowerShell session into a module saved on the local system.
Example:
Establish a remote session with Test01 using New-PSSession. Use Invoke-Command to initiate the use of the BITSTransfer module. Export the commands from the BITSTransfer module into a moduleĀ saved on the local system and called BITSCommands.
$session1 = New-PSSession -ComputerName Test01 Invoke-Command -Session $session1 -ScriptBlock {Import-Module BITSTransfer} Export-PSSession -Session $session1 -Module BITSTransfer -OutputModule BITSCommands -AllowClobber
The exported files are stored within your PowerShell profile folder.
The contents of the BITSCommands.psd1 file are below:
You could make use of this module at a later date with:
Import-Module BITSCommands
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.