Get-Module

Exploring Get-Module in PowerShell

Welcome back to Wahmans PowerShell blog! Today, we are going to dive into a very handy cmdlet: Get-Module. If you’re new to PowerShell or just getting familiar with managing modules, this cmdlet is essential to understanding what modules are loaded in your session and what is available to import.

Description (from Microsoft Docs):

List the modules imported in the current session or that can be imported from the PSModulePath.

Why should I care about Get-Module?

PowerShell modules are collections of related functions, cmdlets, and other resources packaged for reuse. They help you structure your PowerShell scripts efficiently. The Get-Module cmdlet lets you inspect what’s currently available and in use—crucial when you’re trying to troubleshoot, audit, or simply explore the tooling you have at your disposal.

Example 1: List Currently Imported Modules

This is the most basic usage of Get-Module. Run this to see which modules are currently loaded in your PowerShell session.

Get-Module

Output: A list of modules with details like Name, Version, and Path.

Example 2: List All Modules Available for Import

Use the -ListAvailable parameter to list all modules that can be imported from PSModulePath.

Get-Module -ListAvailable

This is great for discovering new modules on your system or verifying installations.

Example 3: Get a Specific Module by Name

If you want to check whether a specific module (e.g. Az) is available or loaded:

Get-Module -Name Az -ListAvailable

This allows you to check if specific modules exist without importing them into your current session.

Example 4: List All Imported Modules with Their Exported Commands

For a more advanced use, let’s combine Get-Module with Select-Object to get a better view of what capabilities have been added by modules:

Get-Module | Select-Object Name, Version, @{Name="Cmdlets"; Expression={$_.ExportedCmdlets.Keys -join ", "}}

This is especially useful when debugging or exploring unfamiliar module functionality.

Wrapping Up

Get-Module is one of those cmdlets that quietly empowers everything under the hood. Whether you’re new to scripting or a seasoned sysadmin, being aware of your current and available modules helps you script smarter and troubleshoot faster.

Happy scripting, and I will see you in the next post!

Leave a Reply

Your email address will not be published. Required fields are marked *