Home Learning Free Tutorials How to Unpack and Install a Module
 

How to Unpack and Install a Module

After you download a PowerShell module, here are the steps to take to make the module work for you.

Note: Since modules are internally just PowerShell scripts, they can only be imported if PowerShell is allowed to run scripts. So if you just started with PowerShell, and you cannot run scripts, you would want to enable PowerShell scripts first by running Set-ExecutionPolicy (for example: Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy RemoteSigned -Force).

Unblock and Unzip the module

PowerShell modules are folders with one or more files. Most of the time, they will be zipped as a ZIP archive. So you need to unpack the file before you can use the module. Before you do that, you will want to unblock the file. Whenever you download something from the Internet or receive as email attachment, Windows blocks the file for security reasons and prevents access to certain files. To unblock downloaded zip files, right-click the file and in the context menu, choose “Properties”. A dialog window opens. Click on the Unblock button in the lower part. If there is no such button, then the file was not blocked.

Next, you can unzip the downloaded file. Right-click it once more, and in the context menu, choose Extract All… If there is no such command, then you may have replaced Windows’ internal ZIP support with some other Unzipping Application. If you cannot find a similar command, try and double-click the file to open it. Then, depending on which applications opens ZIP files for you, look for a way to copy/extract the content.

Identify the module folder

Unzipping the downloaded file creates a new folder, and inside of it, you find the module. The module is just a regular folder. If you are not sure, open the folder and look inside of it. It should at least include one file that has the same name as the folder that contains it.

Importing a module

You can import the module from any place, so you could leave the module folder where it is, or copy it on a USB stick to keep it with you. To import the module and use its new commands, use this code from inside PowerShell:

Import-Module -Name [Path to the module folder]

If the module contains functions that use non-approved verbs (verbs that are not on the list generated by Get-Verb), you will see an orange warning. That’s not a bad thing. It just tells you that some functions may use unusual verbs. If you don’t want to see this warning, try this instead:

Import-Module -Name [Path to module folder] -DisableNameChecking

If you want to actually see the names of the functions imported (added) by the module, add -Verbose:

Import-Module -Name [Path to module folder] -DisableNameChecking -Verbose

Note: while you can import script modules from network locations like a file share, this is not true for binary modules. Binary modules contain files like *.dll. For security reasons implied by .NET framework, most of these can only be loaded from a local path.

Saving modules to default locations

If you plan to use your module on a regular basis, it is better to copy the module folder into one of the default locations so PowerShell can find it and help you use it. The default locations are listed in the PSModulePath environment variable. By default, there is one location in your documents folder for modules that only you want to use, and another one in the windows folder that holds modules accessible for any user. However, you need to be Admin to add/change modules to that location:

PS> $env:PSModulePath -split ';'
C:\Users\Tobias\Documents\WindowsPowerShell\Modules
C:\Windows\system32\WindowsPowerShell\v1.0\Modules\

When you copy a module folder into one of these folders, you gain a lot of benefits:

  • Easier importing: Import-Module now does no longer require the full path. Instead, it is sufficient to submit the module name (the name of the module folder) to load it
  • Easier discovery: Modules stored in the standard locations are included into your module listing that you can display this way: Get-Module -ListAvailable
  • Autoloading: In PowerShell 3.0, you don’t need to import the module manually at all (most of the time). Instead, you can simply use a new command from one of your modules, and PowerShell is smart enough to know which module provides the command – and loads it automatically.

Module  tricks you may want to know

You need to load (import) modules every time you open a new PowerShell session. In PowerShell 3.0, that’s not too much of a hassle as PowerShell loads modules on demand. In all other scenarios, you may want to add your Import-Module command to your profile script.

Your profile script is executed automatically whenever PowerShell starts. The path to your profile script is found in $profile. It may not yet exist, and you may have to create both some of the folders in that path and the profile file itself.

To list all modules that are actually loaded, use Get-Module. To list all modules that are available at one of the default locations, use Get-Module -ListAvailable. And to list the commands contained in a module, try this:

Get-Command -Module [NameOfModule]

More questions?

We are happy to add to this FAQ! If there is still something unclear to you, please leave a comment, and we will address your questions.