Import a Module from Other Computers

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 seemlessly 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

$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.

processes running as ngetchell

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

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.