Loading Modules from Remote Server with PowerShell

Have you ever found yourself trying to run a command, and found out that you need to have modules loaded that are only installed on a remote server. I know I have many times, and trying to found the right module to download at times is nearly impossible.

So starting with PowerShell version 3.0, there is a now way to import a module from a remote machine.  This is a great improvement when you need to collect data from a list of servers and need to use commands the module to gather it.

Loading Modules from a Remote Server

The way to load a module from a remote machine you will need to make a remote PowerShell session to the remote server using the following command:

$RemoteSession = New-PSSession -ComputerName RemoteServer01

If you know the name of the module you can just load it with the following command:

Import-Module -PSSession $RemoteSession -Name WebAdministration

But if you don’t know the name, you can get a list of all available modules on the remote server

Get-Module -PSSession $RemoteSession -ListAvailable
Examples of remote modules
Example of Modules from remote server

Then you can load the required module with the below command:

Import-Module -PSSession $RemoteSession -Name Module_Name

Once the module is loaded all of the commands in the module are available on the local machine.

Example of Remote Module Commands
Example of Remote Module Commands



Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.