Categories

Import and Export PSSession

A couple of comdlets that I’ve not really used much before have just come into prominance for me to solve a problem I’ve been working on.  These cmdlets are:

Import-PSSession
Export-PSSession

The two cmdlets work with commands in a remote session but have subtle differences in terms of what they actually do.

Import-PSSession

This cmdlet imports commands (cmdlets, functions and aliases) from a PSsession on a remote (or local) machine into your current PowerShell session. You must have a remoting session open to the machine from which you want to import and that session must remain open while you are using the commands.

A temporary module is created to hold the imported commands. when you close PowerShell it is removed. Each command has an –AsJob parameter added.

The commands are imported into your session as functions and rely on remoting to access the remote machine. This means that you get inert objects back exactly as if you had run the command on the remote machine through a remoting session.

Export-PSsession

This cmdlet imports commands from a Powershell remotign session BUT it saves them as a module on your local machine. You have to then import the module to use the commands. You will need a remoting session the remote machine for the module to work – Powershell will create it for you when you import the module if one doesn’t exist.

The advantage is that you are importing a local module which should be faster than using import-pssession each time.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>