---
title: "How to Import PowerShell Modules Like a Boss"
description: "Learn how to import PowerShell modules. Understand the cmdlets, parameters and modules available to make your scripts more efficient and powerful."
canonical: "https://adamtheautomator.com/import-powershell-modules/"
---

# How to Import PowerShell Modules Like a Boss

> Learn how to import PowerShell modules. Understand the cmdlets, parameters and modules available to make your scripts more efficient and powerful.

Source: https://adamtheautomator.com/import-powershell-modules/

---

ATA Learning

Tap to hide

[

ATA Learning

](/)

*   [Home](/)
*   [Tutorials](/tutorials/)
*   [Instructors](/author/)
*   [Advertising](/advertising/)
*   [Recommended Resources](/resources/)
*   [About Adam](/about-adam/)

Search for:  

*   [](https://twitter.com/adbertram)
*   [](https://github.com/Adam-the-Automator)
*   [](https://www.linkedin.com/company/adam-the-automator-llc)
*   [](/feed/)

![How to Import PowerShell Modules Like a Boss](https://adamtheautomator.com/wp-content/uploads/2023/03/import-powershell-modules.jpg)

# How to Import PowerShell Modules Like a Boss

[![](https://secure.gravatar.com/avatar/2788bb1a3f735603f81eca51d68daec56a9d97e805a10268fb2c20afcc76b81b?s=192&d=mm&r=g)Nicholas Xuan Nguyen](https://adamtheautomator.com/author/nicholas-xuan-nguyen/)7 March 20236 min. read

Categories: [IT Ops](/category/it-ops/)

Tags:[PowerShell](/tag/powershell/)

Table of Contents

*   [Prerequisites](#prerequisites)
*   [Importing a Single Module](#importing-a-single-module)
*   [Importing Multiple Modules at Once](#importing-multiple-modules-at-once)
*   [Displaying Module Import Details](#displaying-module-import-details)
*   [Reimporting a Module into the Same Session](#reimporting-a-module-into-the-same-session)
*   [Using NuGet Packages to Import PowerShell Modules Manually](#using-nuget-packages-to-import-powershell-modules-manually)
*   [Conclusion](#conclusion)

PowerShell is a phenomenal robust scripting language. But to unlock its potential, you must know how to import the right modules.

In this tutorial, you will learn everything you need to know to import PowerShell modules like a pro. With a deep understanding of cmdlets, parameters, and modules, you can create faster, more efficient, and more effective scripts than ever before.

Read on to supercharge your PowerShell skills and elevate your scripting game to new heights!

Related:[How to Run a PowerShell Script From the Command Line and More](https://adamtheautomator.com/run-powershell-script/)

## Prerequisites

This tutorial will be a hands-on demonstration. To follow along, be sure you have a system with PowerShell installed. This tutorial uses Windows 10 and PowerShell 5.1 as an example, but the same commands should work with most versions of Windows and PowerShell.

Related:[PowerShell 7 Upgrade : A How to Walk Through](https://adamtheautomator.com/powershell-7-upgrade/)

## Importing a Single Module

PowerShell modules contain pre-built code you can use in your PowerShell scripts, saving you time and effort. When you import PowerShell modules, you take advantage of pre-built codes instead of starting from scratch.

But how do you import PowerShell modules? The [`Import-Module` cmdlet](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/import-module?view=powershell-7.3) is the primary way to import modules in PowerShell. Importing a single module is one of the most basic uses of the `Import-Module` cmdlet, which is the first thing you will learn in this tutorial.

Related:[Understanding and Building PowerShell Modules](https://adamtheautomator.com/powershell-modules/)

Open PowerShell as administrator, and run the below `Import-Module` command to search for the [`PSDiagnostics`](https://learn.microsoft.com/en-us/powershell/module/psdiagnostics) module and load it into memory. If successful, the module gets imported, but the command does not produce output.

Related:[Discover How to Run PowerShell as Administrator](https://adamtheautomator.com/powershell-run-as-administrator/)

```powershell
Import-Module PSDiagnostics
```

> _Importing modules from online repositories via the Install-Module cmdlet is highly recommended whenever possible. This cmdlet takes care of dependencies and version management for you._

Once you have imported the module, you can use any of the module’s cmdlets or functions to help you diagnose and troubleshoot issues. The [`Enable-PSTrace`](https://learn.microsoft.com/en-us/powershell/module/psdiagnostics/enable-pstrace) cmdlet is just one example of cmdlets provided by the PSDiagnostics module, which enables diagnostic tracing in PowerShell.

Now, run the following `Enable-PSTrace` command to perform diagnostic tracing and save the results to the specified `-TraceFilePath` (`C:\\MyTrace.log`). This command does not provide output to the console since the results are committed to a file instead.

```powershell
Enable-PSTrace -TraceLevel 1 -TraceFilePath C:\MyTrace.log
```

> _Some modules may require additional configuration or setup before you can use them. Be sure to read the documentation provided with the module to understand any prerequisites or requirements._

## Importing Multiple Modules at Once

Importing a single module works fine. But when you often need to import multiple modules in one go, the task is also within the powers of the `Import-Module` cmdlet.

Importing multiple modules is a great way to save time and effort in PowerShell. But how exactly? You will specify the module names separated by commas.

Run the below command to search for multiple modules (`[Dism](https://learn.microsoft.com/en-us/windows-hardware/manufacture/desktop/what-is-dism?view=windows-11), [PowerShellGet](https://adamtheautomator.com/powershell-gallery), [PSReadline](https://learn.microsoft.com/en-us/powershell/module/psreadline)`) and load them into memory. Like importing a single module, this command does not provide output.

Related:[The Ins-and-Outs of PSReadline in PowerShell](https://adamtheautomator.com/psreadline/)

```powershell
Import-Module Dism, PowerShellGet, PSReadline
```

## Displaying Module Import Details

As previously mentioned, successful module import does not provide output. But admit it. You would be skeptical whether the module was indeed imported or not.

The `-Verbose` parameter is a useful option that you can use with many PowerShell cmdlets and functions, including the `Import-Module` cmdlet. This parameter tells PowerShell to display detailed information about the command as it is being executed. In turn, you get the valuable feedback you can use for troubleshooting and debugging.

Run the following command to import the [`SmbShare`](https://learn.microsoft.com/en-us/powershell/module/smbshare) module, appending the `-Verbose` parameter to print the module import details.

```powershell
Import-Module SmbShare -Verbose
```

As you can see below, the `-Verbose` parameter provides detailed information about the module file being loaded and various functions being imported from the module. This information can help understand the inner workings of the module.

In this case, the `SmbShare` module provides cmdlets for managing SMB shares on Windows machines. These cmdlets include but are not limited to [`New-SmbShare`](https://learn.microsoft.com/en-us/powershell/module/smbshare/new-smbshare) (creating new shares) and [`Remove-SmbShare`](https://learn.microsoft.com/en-us/powershell/module/smbshare/remove-smbshare) (removing existing shares).

![Displaying module import details](https://adamtheautomator.com/wp-content/uploads/2023/03/image-20.png)

Displaying module import details

## Reimporting a Module into the Same Session

Whether your module is acting up or you just want to ensure you are using the most up-to-date version of your module, reimporting a PowerShell is conducive. How? By appending the `-Force` parameter to the `Import-Module` command.

This `-Force` parameter allows you to continue using the cmdlets and functions provided by the module without having to close and reopen your PowerShell session.

> _One common use case for reimporting a module is when you are developing and making changes to a module. You can reimport the module into your current session to test those changes before finalizing them._

Run the following command to `-Force` PowerShell to remove, and reimport the `SmbShare` module from its original location.

The `-Prefix` parameter allows you to specify a prefix for the cmdlets and functions imported from the module. In this case, all imported cmdlets and functions will be preceded by `New`. This parameter can be useful for avoiding conflicts with existing cmdlets or functions in your session.

For example, the `Get-SmbShare` cmdlet in the original module will become `Get-NewSmbShare` in the reimported module.

```powershell
Import-Module SmbShare -Force -Prefix New
```

Now, run the [Get-Command](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/get-command) below to retrieve a list of all the cmdlets and functions provided by the SmbShare module selected ([Select-Object](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/select-object)) by Name.

```powershell
Get-Command -Module SmbShare | Select-Object Name
```

Related:[How To Use the PowerShell Expand Property for Select-Object](https://adamtheautomator.com/powershell-expand-property/)

Below, you can see that the SmbShare module’s cmdlets now have the prefix **New** added to their names. This output confirms the module has been reimported successfully.

![Verifying the SmbShare module has been reimported](https://adamtheautomator.com/wp-content/uploads/2023/03/image-21.png)

Verifying the SmbShare module has been reimported

## Using NuGet Packages to Import PowerShell Modules Manually

So far, you have successfully imported modules from the PowerShell Gallery. But what if the module you are looking for is not there?

You can manually install and import PowerShell modules from a NuGet package. In the PowerShell context, a NuGet package is a collection of files that include a PowerShell module along with any dependent modules or libraries required for the module to work.

To import a module from a NuGet package, you need to manually download, extract, and install the NuGet package with the following steps:

1\. Navigate to the Azure [PowerShell Gallery](https://www.powershellgallery.com/packages/Az.Automation/1.9.1) page of the Az.Automation module.

2\. Next, click the **Manual Download** tab → **Download the raw nupkg file** to download the package. This tutorial uses the Az.Automation 1.9.1 module from the Azure PowerShell gallery as an example. But the same steps apply to other NuGet packages.

![Downloading the raw NuGet package (nupkg) file](https://adamtheautomator.com/wp-content/uploads/2023/03/image-22.png)

Downloading the raw NuGet package (nupkg) file

3\. Once downloaded, run the below [`Unblock-File`](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/unblock-file) command, which does not provide output, but unblocks the downloaded _.nupkg_ file. Be sure to change the file path with the one where you downloaded the package.

Unblocking the package is necessary. Why? PowerShell may not allow the execution of files downloaded from the internet as a security measure to prevent the execution of potentially harmful script

```powershell
Unblock-File -Path C:\PSModules\az.automation.1.9.1.nupkg
```

4\. Now, unzip the downloaded _.nupkg_ file to a folder on your local machine. You may need a compression/decompression tool such as 7-zip or WinRAR to unzip the package. A NuGet package is a ZIP archive containing a collection of files that comprise a module.

Related:[Introducing PowerShell Unzip and Zip Commands on Archives](https://adamtheautomator.com/powershell-unzip/)

5\. Delete the following contents from the extracted folder.

Extracted contents of a NuGet package include some metadata and files that are not needed for manual module installation.

| Name | Type |
| --- | --- |
| \_rels | Folder |
| Package | Folder |
| \[Content\_Types\].xml | XML File |
| Az.Automation.nuspec | XML Manifest File |

![Deleting unnecessary contents from the extracted NuGet package folder](https://adamtheautomator.com/wp-content/uploads/2023/03/image-23.png)

Deleting unnecessary contents from the extracted NuGet package folder

6\. Rename your extracted folder with a more descriptive name like _az.automation_ to avoid any errors that might come up. Remember to keep all letters lowercase and refrain from using special characters in its name.

7\. Next, run the `$env:PSModulePath` command below to find your current shell module’s paths. This command returns a list of all default module paths on your system. PowerShell searches these paths to load modules automatically when the module name is specified in a script or command.

```powershell
$env:PSModulePath
```

Take note of the paths, as you will need them in the following step.

![Finding out where your modules’ paths are located](https://adamtheautomator.com/wp-content/uploads/2023/03/image-24.png)

Finding out where your modules’ paths are located

Related:[PowerShell Environment Variables: The Ultimate Guide](https://adamtheautomator.com/powershell-environment-variables/)

8\. Copy the newly-named folder (_az.automation_) to one of the directories you noted in step seven. Doing so defines the module’s scope (specific or all users).

| Path | Function |
| --- | --- |
| _C:\\Users\\admin\\Documents\\WindowsPowerShell\\Modules_ | Makes the module available for the specific user account (admin). This tutorial uses this location as an example. |
| _C:\\Program Files\\WindowsPowerShell\\Modules_ | Makes the module available for all user accounts on your local machine. |

9\. Now, run the below command to install and import the module (az.automation) into your PowerShell session. Be sure to replace az.automation with the actual name of your module.

```powershell
Import-Module -Name az.automation -Verbose
```

![Installing and importing a module from a NuGet package](https://adamtheautomator.com/wp-content/uploads/2023/03/image-25.png)

Installing and importing a module from a NuGet package

10\. Finally, run the following [Get-Module](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/get-module) command to verify if the module (az.automation) has been imported successfully.

```powershell
Get-Module -Name az.automation
```

![Verifying the module has been imported successfully](https://adamtheautomator.com/wp-content/uploads/2023/03/image-26.png)

Verifying the module has been imported successfully

Perhaps you do not want to rely on auto-discovery. If so, specify the exact file location (_C:\\az.automation_) when importing the module.

```powershell
Import-Module -Name C:\az.automation -Verbose
```

![Specifying the exact file location when importing a module](https://adamtheautomator.com/wp-content/uploads/2023/03/image-27.png)

Specifying the exact file location when importing a module

## Conclusion

With conjoined functions or grouped code, PowerShell modules are game changers. And in this tutorial, you have learned ample ways to import PowerShell modules into your sessions, including manually importing modules from a NuGet package. You have also touched on different parameters controlling the importing process.

By mastering these techniques, you can easily import and use modules to enhance your automation scripts. But the learning does not have to stop there. Why not take your PowerShell module management skills to the next level by learning to [export module members](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/export-modulemember?view=powershell-7.3)?

Share this article

[Share on X](https://twitter.com/intent/tweet?url=https%3A%2F%2Fadamtheautomator.com%2Fimport-powershell-modules%2F&text=How%20to%20Import%20PowerShell%20Modules%20Like%20a%20Boss)[Share on Facebook](https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Fadamtheautomator.com%2Fimport-powershell-modules%2F)[Share on LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fadamtheautomator.com%2Fimport-powershell-modules%2F)

## Related Posts

![](https://adamtheautomator.com/wp-content/uploads/publisher/3f95d9c85b2b81e69730da4c690758c2/4afeea42b7f854d23285b281664351779f042510f1e3a1d766d02cfa39b711a8.jpg)

### [Find and Disable Every Inactive AD Computer with PowerShell](/find-inactive-computers-active-directory/)

Find inactive computer accounts in Active Directory with Search-ADAccount, then disable and quarantine them with PowerShell in steps you can undo.

![](https://adamtheautomator.com/wp-content/uploads/publisher/3f95d9c85b2b814eba23fbf8d18b64a2/ade916ad78256face2456a10aacfbb82051f4957bf03d6f163193b25395e5183.jpg)

### [Back Up and Restore Every Group Policy Object in PowerShell](/backup-restore-gpos-powershell/)

Back up every Group Policy Object with Backup-GPO, restore one or all with Restore-GPO, and recover a deleted GPO with Import-GPO and New-GPLink.

![](https://adamtheautomator.com/wp-content/uploads/publisher/3f95d9c85b2b8181be1be294c37c6724/0ba6a36aaba4a30390fca48d395a19d38846d030302d345372b68b077c3a5cdc.jpg)

### [Find Stuck DFS Replication Backlogs with PowerShell](/dfs-replication-backlog-powershell/)

Find out whether DFS Replication is caught up. Get-DfsrBacklog reads the full file count past the 100-file limit, then a loop checks every group.

## Categories

*   [IT Ops](/category/it-ops/)
*   [Cloud](/category/cloud/)
*   [DevOps](/category/devops/)
*   [Home Ops](/category/home-ops/)
*   [Information Security](/category/infosec/)
*   [Software Development](/category/software-development/)

## Site

*   [Home](/)
*   [Tutorials](/tutorials/)
*   [Instructors](/author/)
*   [Advertising](/advertising/)
*   [Recommended Resources](/resources/)
*   [About Adam](/about-adam/)

Copyright 2026© ATA Learning | [Privacy Policy](/privacy/)
