PowerShell Import-Module

Introduction to PowerShell’s Import Modules

Clever programmers are making more and more modules for PowerShell. Make sure you benefit from their manifest, binary and script modules.

You have probably used existing cmdlets such as Get-Process, Get-ChildItem or Restart-Service.  Well, Import-Module extends your toolbox by adding specialist functions such as Get-RegString.  The hardest part – and that’s not too difficult – is locating suitable modules to download.

Import-Module Checklist


Case Study: Import-Module PSRemoteRegistry

We are going to work with a manifest module called PSRemoteRegistry, which will provide PowerShell with over 20 new Verb-Noun commands.

Preamble:  Check that there are no registry cmdlets or functions already installed.

# Negative Experiment
Get-Command -Module PSRemoteRegistry

Note 1: I expect that no cmdlets or functions are present at this stage, even if you try Get-Command get-*reg*.

Download Your Module: Rather than giving you a link to Codeplex, where you may not have an account, I suggest that you find a suitable source by googling: ‘Download PSRemoteRegistry’.

Install PSRemoteRegistry:  After double-clicking the .msi file, recommend that you direct the install to this path:
Alternatively, you could copy the files to:
%SystemRoot% \WindowsPowerShell\v1.0\Modules\

Note 2:
$home corresponds to C:\Users\Guy  (or whatever is the username)
%SystemRoot is usually at C: \Windows \sytem32\

While this is best practice it is possible to use Import-Module to add manifests at other location.

The Main Event – Import-Module

Having downloaded and installed my module, I like to run a quick check with Get-Module to see if PSRemoteRegistry is ready and waiting for me to use.

# Import-Module cmdlet in action
Get-Module ; "Count " +(Get-Module).count
Start-Sleep -s 7
Import-Module PSRemoteRegistry -verbose
Write-Host `n"– After import –" `n
Get-Module ; "Count " +(Get-Module).count

Note 3: All you really need is: Import-Module PSRemoteRegistry.

List the Resulting PSRemoteRegistry Functions (cmdlets)

Now that your new cmdlets, or to give them the correct name – functions, have arrived, let us see what we have.

# To check what the PSRemoteRegistry contains
Get-Command -Module PSRemoteRegistry | Ft Name, CommandType -auto

Get-RegBinary           Function
Get-RegDefault          Function
Get-RegDWord           Function
Get-RegExpandString  Function
Get-RegKey               Function
Get-RegMultiString      Function
Get-RegQWord           Function
Get-RegString            Function
Get-RegValue             Function
New-RegKey               Function
Remove-RegKey          Function
Remove-RegValue       Function
Set-RegBinary            Function
Set-RegDefault           Function
Set-RegDWord            Function
Set-RegExpandString   Function
Set-RegMultiString      Function
Set-RegQWord            Function
Set-RegString             Function
Test-RegKey               Function
Test-RegValue            Function

Note 4:  Another way of researching your module is with Get-Module -List.  I find the best way to see the properties is to pipe the output into Format-List -properties *.  See more on this PowerShell Module technique.

Note 5: See these new modules in action with Set-RegString.

Guy Recommends:  A Free Trial of the Network Performance Monitor (NPM)Review of Orion NPM v11.5 v11.5

SolarWinds’ Network Performance Monitor will help you discover what’s happening on your network.  This utility will also guide you through troubleshooting; the dashboard will indicate whether the root cause is a broken link, faulty equipment or resource overload.

What I like best is the way NPM suggests solutions to network problems.  Its also has the ability to monitor the health of individual VMware virtual machines.  If you are interested in troubleshooting, and creating network maps, then I recommend that you try NPM now.

Download a free trial of Solarwinds’ Network Performance Monitor

Loading Modules Automatically Through Profile

PowerShell has a startup folder, which we can access it via the $Profile variable.  There are two profile files, one for PowerShell’s ISE and another for the plain command-line PowerShell.  Fortunately, you can launch notepad and edit either of them.

The Plan
Open Microsoft.PowerShell_profile with notepad
Append an Import-Module command
See details of how to modify a PowerShell Profile.

Research More Parameters for Import-Module

Get-Help Import-Module -full

Note 6: As usual, Get-Help comes up with useful parameters such as -verbose.  Furthermore, the -full switch supplies interesting examples, such as:
Get-Module -ListAvailable | Import-Module

More Help with About_Module
I am impressed with advice about using and installing modules provided in the ‘about_module’ help file.  Just type:

Get-Help About_Module

It reminds us how to install, import and the find your module’s commands.

Get more help on PowerShell’s About_ files »

See Other Members of the Module Family

Get-Command -Noun module

  • Get-Module
  • New-Module
  • Import-Module
  • Remove-Module

Note 7: Remove-Module is useful for testing.  I often need to reset conditions so that I can experiment with Import-Module once more.

See examples of Codeplex with Import-Module »

Summary of PowerShell Import-Module

Have you ever been 25 and wish you could be 16 again?  Well, if I had my time with PowerShell again I would have imported more modules earlier in my career. 

If you like this page then please share it with your friends


See more Microsoft PowerShell tutorials

PowerShell Tutorials  • Methods  • Cmdlets  • PS Snapin  • Profile.ps1  • Exchange 2007

Command & Expression Mode  • PowerShell pipeline (|)  • PowerShell ‘where‘  • PowerShell ‘Sort’

Windows PowerShell Modules  • Import-Module  • PowerShell Module Directory 

If you see an error of any kind, do let me know.  Please report any factual mistakes, grammatical errors or broken links.