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.
- Research Suitable PowerShell Modules Online
- Download Your Module:
- Install Your Module PSRemoteRegistry
- Get-Module -List
- The Main Event – Import-Module
- List the Resulting PSRemoteRegistry Functions
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:
$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.
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.
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
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.
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.
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.
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:
It reminds us how to install, import and the find your module’s commands.
See Other Members of the Module Family
Get-Command -Noun 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.
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
If you see an error of any kind, do let me know. Please report any factual mistakes, grammatical errors or broken links.