Modules
Scope: finding, installing, and using PowerShell modules. All examples were run with PowerShell 7.5.
What a module is
A module is a package of commands — functions, cmdlets, aliases
— you load into your session. The Az modules (Azure),
Microsoft.Graph (Microsoft 365), Pester (testing), and
thousands of community modules all work this way.
Finding and installing
Find-Module -Name Pester | Select-Object Name, Version
Install-Module -Name Pester -Scope CurrentUser
Import-Module Pester
Find-Modulesearches the PowerShell Gallery (powershellgallery.com) — the npm/PyPI of PowerShell.-Scope CurrentUserinstalls to your profile, no admin needed. Prefer it over system-wide installs.Import-Moduleloads it into the session. Many modules auto-load on first use, but explicit imports are clearer in scripts.
First time, you'll be asked to trust the gallery repository — answer yes (it's Microsoft's official registry).
Using installed modules
Get-Module -ListAvailable | Select-Object Name, Version
Get-Command -Module Pester
Get-Module -ListAvailable shows what's installed;
Get-Command -Module <name> shows what a module provides.
Module scopes and versions
Install-Module -Name Az -Scope CurrentUser -RequiredVersion 12.0.0
Update-Module -Name Az
Uninstall-Module -Name Az -RequiredVersion 11.0.0
Multiple versions can coexist; Import-Module -RequiredVersion
picks one. Update-Module upgrades. Clean up old versions
occasionally — Az especially accumulates them.
Writing your own (the 30-second version)
# MyTools.psm1
function Get-Greeting {
param([string]$Name = "stranger")
"Hello, $Name!"
}
Export-ModuleMember -Function Get-Greeting
Import-Module ./MyTools.psm1
Get-Greeting -Name "Ada"
A .psm1 file is a module; Export-ModuleMember controls
what's public. Add a .psd1 manifest (New-ModuleManifest)
when you want versioning and metadata.
Trust notes
The Gallery is large and community-driven — same caution as npm applies: prefer modules from Microsoft or well-known publishers, check download counts and recent updates, and don't install obscure modules on production boxes without a look at the code.
Check
- [ ] You can find, install (CurrentUser scope), and import a module
- [ ] You know what the PowerShell Gallery is
- [ ] You can list a module's commands
Next: Error Handling.