March 14, 2018 ~ 1 min read

Import a Module from Other Computers


PowerShell comes with a simple way to install a module using PowerShellGet and the Find/Install Module cmdlets. Did you know however that you can import modules, over the network, from a computer that already has them installed? They aren’t installed locally and when you run the commands, PowerShell will seamlessly run them in the PowerShell process running on the remote computer.

I am constantly hopping onto different computers at work and not all of the computers have the RSAT tools for Active Directory administration. Using the Import-Module with the PSSession parameter lets me use the local console for administration.

$Session = New-PSSession -Computername DC
Import-Module -PSSession $Session -Name ActiveDirectory

Get-ADUser -identity ngetchell

The results come back to your own console even though the module resides on the remote box. If you’ve ever administered an Exchange Online tenant from PowerShell you’ve likely used this feature. Here, we import the entire session, not just one module into your current, local session.

$Params = @{ 
    ConfigurationName = 'Microsoft.Exchange' 
    Authentication    = 'Basic'
    AllowRedirection  = $true 
    AllowClobber      = $true 
    ConnectionUri     = 'https://outlook.office365.com/powershell-liveid/' 
    Credential        = ( Get-Credential ) 
} 
$Session = New-PSSession @Params 
Import-PSSession $Session

Headshot of Nicholas Getchell

Hi, I'm Nick. I'm a DevOps Engineer. Read my blog or check out my open source projects at GitHub. Reach out to me on LinkedIn or Bluesky.