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 #58 Export-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 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.

    Export-PSSession1

    The contents of the BITSCommands.psd1 file are below:

    Export-PSSession2

    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.

    1000 things 1% better!

    Leave a reply