How to import a PowerShell module from a remote computer

In this quicktip we will demonstrate how to make a PowerShell module available on a computer by importing it from another computer where the module is already installed.

For this example we will be importing the ActiveDirectory module. If you want make the ActiveDirectory module available on Computer1 by importing it from DomainController1, you have to perform following steps on Computer1:

First we will create a PowerShell session to DomainController1 and save it to the variable $DomainController1Session.

$DomainController1Session = New-PSSession -Computername DomainController1

Now we will import the ActiveDirectory module in the session we just created.

Invoke-Command -Command {Import-Module ActiveDirectory} -Session $DomainController1Session

Finally, we will import this session in our local PowerShell session. The -Prefix DC1 will add a prefix to each imported cmdlet (Get-ADUser becomes Get-DC1ADUser for instance). This is not mandatory, but it’s a good way to differentiate local from remote (imported) commands.

Import-PSSession -Session $DomainController1Session -Module ActiveDirectory -Prefix DC1


Leave a Reply

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