Our website relies on funding from our readers, and we may receive a commission when you make a purchase through the links on our site.

How to Install PowerShell Modules: Step by Step 

by John Cirelly - Last Updated: July 21, 2023

How to Install PowerShell Modules Step by Step

A group of connected Windows PowerShell members, such as cmdlets, providers, functions, workflows, aliases, and variables, are grouped in a PowerShell module. Implementation of the components that make up a package can take place either in the form of a PowerShell script, a compiled DLL, or both of these. Typically, these components are arranged in a single directory. The primary purpose of a module is to facilitate the modularization of code using Windows PowerShell.

If you define a collection of related script files, assemblies, and resources as a module, you will have a much easier time referencing, loading, persisting, and sharing your code than you would if you did not have this definition. Those who write commands, for instance, can use modules to organize their commands and share them with others. Those who receive modules, on the other hand, can add the commands contained in the modules to their PowerShell sessions and use them in the same manner as the built-in commands.

There are several hundred cmdlets included in the version of PowerShell that is distributed with Windows. These cmdlets can assist you in performing fundamental operations such as reading files, generating registry keys, pinging computers, connecting to distant systems, and many other similar activities.

However, the out-of-the-box PowerShell cmdlet that comes with the language cannot handle all of the things that you want to do with it. It is necessary to install modules that contain commands that provide you the capability you need to carry out operations that are not covered by the built-in PowerShell functions.

In the following article, you will find a detailed walkthrough that will show you how to install PowerShell modules.

What exactly are these “PowerShell Modules”

PowerShell modules are nothing more than a collection of scripts that carry out the same task under a different name.

Let’s look at an example of this to better comprehend it.

You are a specialist in the PowerShell scripting language, and you write scripts to solve a variety of issues. On the other hand, they may be saved across multiple devices, including yours, servers, the devices of your coworkers, etc.

In other words, the scripts are dispersed in a variety of locations, and you are unable to determine which script is housed in which location. When you want to repurpose scripts, this presents a difficulty for you. In addition to this, it turns into a difficulty when you start developing complete solutions that may be implemented across the entire firm.

PowerShell modules are a streamlined solution to this situation because they combine similar scripts or those that are geared towards solving different aspects of the same problem into a cohesive unit. This gives you better control over its storage and usage, which makes it easy to share your code with other people, reuse it when necessary, and provides a structure to the code.

In general, a PowerShell module may contain the following:

  • One or more scripts are written in PowerShell.
  • Additional file and assembly options may be required by the scripts.
  • The metadata of the aforementioned files, including description, author, and version numbers, are stored in a Manifest file.
  • A directory that contains the aforementioned files is located in a location that can be accessed by PowerShell.

The four most important types of PowerShell instructions are known as cmdlets, PowerShell functions, executable programs, and PowerShell scripts. In addition, PowerShell is a cross-platform, open-source program that can create backups of the entire database as well as the transaction log.

Because of its remarkable capabilities, such as Script debugging, Automatic loading system, PowerShell remoting, steppable pipeline, Network File Transfer services, background and scheduled jobs, Error-handling mechanism, Constrained run spaces, and many more, PowerShell has gained a large user base and established itself as an industry leader

Method 1: Installing a Module from the PowerShell Gallery 

The PowerShell Gallery is an online package repository for PowerShell that enables users to download and use scripts, modules, and DSC resources. These were written by Microsoft in collaboration with the PowerShell community. You can search for packages in the PowerShell Gallery using the following criteria:

  • Utilizing the Search function located on the front page of the PowerShell Gallery
  • Exploring the Scripts and Modules available for download on the Packages page
  • Executing, depending on the type of package, either the Find-Module, Find-DscResource, or Find-Script cmdlets

When you have found a package that piques your interest, you can find out more information about it by viewing the metadata that was submitted along with the package on the page that is dedicated specifically to the item within the Gallery.

It is also recommended that you download the package from the Gallery to conduct further examination. To accomplish this, you will need to execute either the Save-Module or Save-Script cmdlet, depending on the kind of package you are working with. This enables you to save the package to your local computer to inspect its contents without having to install it.

It is recommended that you install PowerShell modules through the PowerShell Gallery as this is the most straightforward method. Installing a package or module obtained from the Gallery requires the use of either the Install-Module or Install-Script cmdlet, depending on the type of package being utilized.

  • By default, the module will be installed to $env: ProgramFilesWindowsPowerShellModules after being installed with the Install-Module command. To do this, you need an account with administrator privileges. When the -Scope CurrentUser argument is included in the command, the module will be placed in the following location:
$env: USERPROFILEDocumentsWindowsPowerShellModules
  • When you use the Install-Script command, the script will be installed in the $env: ProgramFilesWindowsPowerShellScripts directory by default. Additionally, this calls for an account with administrator privileges. Whenever you run a script with the -Scope CurrentUser argument, it will be installed in the following location:
$env: USERPROFILEDocumentsWindowsPowerShellScripts
  • By default, the Install-Module and Install-Script commands will install the most recent available version of a package. Include the -RequiredVersion argument in your call to configure the package if you need to use an earlier version of the software.

In addition, before you can install a module, you need to be familiar with both the name of the module and the command that will install it. On the Gallery page, you will see the command that you need to run to install the module. In this demonstration, we will implement NetworkingDsc, a module that we discovered in the Gallery and want to use. To accomplish this, type the following command into your terminal:

The syntax for installing the module is: install-module -name NetworkingDsc -required version 8.2.0

  • You might receive the notification that the NuGet provider is necessary to continue running, but this will depend on the NuGet provider that you are currently using. Because PowerShellGet is dependent on a service known as Nuget, you may be forced to update to the most recent version before continuing. If you encounter the question “Do you want PowerShellGet to install and import the NuGet provider now?” then you should type “Y” followed by the Enter key. \
  • Another message may pop up asking you to confirm that you do wish to install the modules from “PSGallery”, but this time it will depend on the parameters you have chosen. To proceed, press the Enter key after typing the letter Y.
  • The installation of the NetworkingDsc module will start as soon as this command is executed, and you will be able to observe its progress by observing the loading text at the top of the PowerShell window. You will be able to confirm that the installation was successful once it has been finished by executing the following command: Get-Module -ListAvailable.

Method 2: Manually installing the modules

You will be required to make use of this method if the module is not included in the PowerShell gallery.

  • Establish the Location of the Install

You wish to put newly downloaded modules in a directory that is specified by the PSModulePath environment variable. Execute the following command to view the value of the PSModulePath property.

$Env:PSModulePath

This is the output that was produced when I ran that command on my machine. You need to notice comparable outcomes. There could be multiple other routes indicated, but the two primary routes that you ought to take are as follows:

  • C:\Users\userprofile\Documents\WindowsPowerShell\modules
  1. Navigate to the following directory: C:Program FilesWindowsPowerShellModulesModule Folder>Module Files>

If you just want the module to be accessible to a certain user, the first path is the one you should choose. Make sure you follow the second step if you want the module to be accessible to all users.

So, what exactly is the purpose of the other routes?

The directory that can be found below is only accessible by modules that come pre-installed on Windows. It is strongly advised by Microsoft that you do not utilize this location.

$PSHome\Modules (percent Windir percent \System32\WindowsPowerShell\v1.0\Modules)

You are also free to create your pathways, but unless you have a really specific requirement, I would recommend that you stick to the two that I have listed.

Other paths listed in your environment variable may come from programs that you’ve installed on your computer if you notice such paths listed there. Some apps will install PowerShell commands, and those commands will be added to the variable automatically.

Let’s go on to the next step now that we have a better idea of where to store the new modules.

  1. Copy the new module to the path

Now that the new module has been successfully downloaded, the next thing I need to do is copy it into one of the two locations that were outlined in step 1. Because I plan to make it accessible to all users, I’m going to copy and paste it here.

Modules can be found in the C: ProgramFilesWindowsPowerShell folder.

The solution is right there; all you need to do is cut and paste the module into the route. The process of adding new modules is finished at this point. First, let’s make sure PowerShell can see the newly installed module by executing the following command:

Get-Module -ListAvailable

The paths that are specified in the environment variable will be inspected by this command to determine which modules to use. When I execute this command, the results are displayed in the snapshot that can be found below. I can confirm that PowerShell is now able to access the newly added module, which is NTFSSecurity.

Once this last step is complete, then we will be able to utilize the new commands; however, the new module has already been installed.

  • Import the new module

Importing a module into our session loads it into active memory so that we can access it while we are working with it.

Execute the following command to import.

ZAAZImport-module -name ModuleName

For the module that I’m demonstrating with this example, the format would be as follows:

Import-module NTFSSecurity

That concludes everything and the newly developed module can now be put to use.

Conclusion

The widely used PowerShell program is compatible with all major operating systems, including Linux and macOS X. The user can easily switch to PowerShell to speed up the process of creating scripts or issuing commands, therefore eliminating the need to carry out laborious and time-consuming operations.

In conclusion, PowerShell modules are a convenient method to organize all of your comparable scripts in a single location, making it easier to call upon them when necessary. Manual installation and installation directly from the PowerShell Gallery are the two primary approaches to installing the modules. We have high hopes that the thorough methods will assist you in rapidly establishing your modules.

PowerShell Modules Installation FAQs

How do I install a PowerShell module?

To install a PowerShell module, you can use the Install-Module cmdlet in PowerShell. For example, to install the Azure PowerShell module, you can run the following command: Install-Module -Name Az.

What is the PowerShell Gallery?

The PowerShell Gallery is a public repository of PowerShell modules and scripts. It can be accessed from within PowerShell using the Find-Module and Install-Module cmdlets.

How do I search for a PowerShell module in the PowerShell Gallery?

To search for a PowerShell module in the PowerShell Gallery, you can use the Find-Module cmdlet. For example, to search for a module that includes the word "SQL," you can run the following command: Find-Module -Name *SQL*.

How do I install a specific version of a PowerShell module?

To install a specific version of a PowerShell module, you can use the Install-Module cmdlet with the -RequiredVersion parameter. For example, to install version 1.3.0 of the PowerShellGet module, you can run the following command: Install-Module -Name PowerShellGet -RequiredVersion 1.3.0.

How do I update a PowerShell module?

To update a PowerShell module, you can use the Update-Module cmdlet. For example, to update the Azure PowerShell module, you can run the following command: Update-Module -Name Az.

How do I uninstall a PowerShell module?

To uninstall a PowerShell module, you can use the Uninstall-Module cmdlet. For example, to uninstall the Azure PowerShell module, you can run the following command: Uninstall-Module -Name Az.

Can I install PowerShell modules from sources other than the PowerShell Gallery?

Yes, you can install PowerShell modules from sources other than the PowerShell Gallery. For example, you can install modules from a network share or from a file on your local system.

How do I import a PowerShell module?

To import a PowerShell module, you can use the Import-Module cmdlet. For example, to import the Azure PowerShell module, you can run the following command: Import-Module -Name Az.

How do I list all installed PowerShell modules?

To list all installed PowerShell modules, you can use the Get-Module cmdlet. For example, to list all installed modules, you can run the following command: Get-Module -ListAvailable.

What is the difference between a binary module and a script module?

A binary module is a compiled module that is written in a language other than PowerShell, such as C# or VB.NET. A script module is a PowerShell script that defines a module.

How can I share a PowerShell module with others?

You can share a PowerShell module with others by publishing it to the PowerShell Gallery or by distributing it as a file or network share. You can also create a NuGet package that includes the module and any dependencies and share that with others.