Modules are how PowerShell code is shared, versioned and reused across scripts and teams.
A module is a package of commands. Most of PowerShell itself ships as modules, and thousands more (Az for Azure, Pester for testing, PSScriptAnalyzer for linting, Microsoft.Graph) are published on the PowerShell Gallery.
In PowerShell 7.4+ the PSResourceGet cmdlets manage them: Find-PSResource, Install-PSResource -Scope CurrentUser, Update-PSResource. The older PowerShellGet commands (Install-Module) still work. Modules are found in the folders listed in $env:PSModulePath and auto-loaded the first time you use one of their commands, so Import-Module is mostly needed for modules outside those folders or to reload with -Force during development.
Your own script module is a .psm1 file with functions; put it in a folder of the same name. Control what is public with Export-ModuleMember or, better, a manifest (.psd1) created by New-ModuleManifest, which declares the version, author, dependencies and FunctionsToExport. Explicit exports keep helper functions private and make auto-loading fast.
Common layout: one function per .ps1 file in Public/ and Private/ folders, dot-sourced by the .psm1, plus Pester tests. Get-Command -Module Name lists a module's commands and Get-Module shows what is loaded.
Example
Find-PSResource -Name Pester # search the PowerShell Gallery
Install-PSResource -Name Pester -Scope CurrentUser # PSResourceGet (7.4+)
Get-Module -ListAvailable Pester | Select-Object Name, Version
# Your own module: MyTools/MyTools.psm1
# function Get-Answer { Get-InternalValue }
# function Get-InternalValue { 42 } # helper, kept private
New-ModuleManifest ./MyTools/MyTools.psd1 -RootModule MyTools.psm1 `
-ModuleVersion 1.0.0 -FunctionsToExport Get-Answer
Import-Module ./MyTools -Force
Get-Answer # 42
Get-Command -Module MyTools | Select-Object -ExpandProperty Name # Get-Answer
Get-InternalValue # error: not recognized (private)
$env:PSModulePath -split [IO.Path]::PathSeparator # where modules are discoveredRemember
- Install-PSResource gets modules from the PowerShell Gallery
- Modules on $env:PSModulePath auto-load on first use
- A .psd1 manifest declares version and exported functions
Watch out for
- Exporting every function with wildcards, which exposes helpers and slows auto-loading.