Import PowerShell module from a remote machine

Load a PowerShell module from a remote server.

John Savill

March 20, 2017

1 Min Read
Import PowerShell module from a remote machine

Q. How can I import a PowerShell module from a remote machine?

A. It is very common to create a remote session on a machine and in that session you can then use the modules on that remote server. Another option is to import remote modules on to your local machine via the remote session. When that module is utilized on the local machine it actually executes via the remote session.

To do this create a session then import a module via the session, for example:

$adsess = New-PSSession -ComputerName savdaldc01
Import-Module -Name ActiveDirectory -PSSession $adsess
Get-Module
Get-ADUser -Filter *
Remove-Module ActiveDirectory

It's also possible to prefix modules loaded from remote servers to differentiate from local modules, e.g.

Import-Module -Name ActiveDirectory -PSSession $adsess -Prefix OnDC
Get-OnDCADUser -Filter * #I don't have regular Get-ADUser anymore
Remove-Module ActiveDirectory
Remove-PSSession $adsessĀ 

About the Author(s)

Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.

You May Also Like