- Courses
- đź’»Programming Languages
- 🪟PowerShell
- PowerShell Scripting at Scale
- Modules & Packaging
- Modules
On this page
PowerShell Modules Explained
Updated on June 23, 2026
By Enrico Hochkoeppler
Web Developer & TutoriaLibre Founder
A PowerShell module is a self-contained, reusable unit of code that can include cmdlets, providers, functions, variables, aliases, and other resources. Modules are the professional way to package PowerShell code for reuse, versioning, and distribution. A module can be a single .psm1 script file, a compiled .dll binary assembly, or a folder containing multiple files with a .psd1 manifest that describes the module's contents and dependencies. By default, PowerShell automatically loads an installed module the first time you use a command from that module. Modules transform PowerShell from a scripting language into a scalable automation platform, enabling enterprise-level code organization, team collaboration, and maintainable automation frameworks.
The Purpose of a Module​
A module exists to solve several problems that arise when scripts grow in size and complexity:
- Reusability — functions can be shared across multiple scripts or teams
- Organization — related functionality is grouped together
- Encapsulation — internal helper functions can be hidden
- Versioning — different versions can coexist and be managed
- Distribution — modules can be published to internal or public repositories
- Maintainability — updates can be made in one place instead of many
Modules elevate PowerShell from a scripting tool to a full automation framework.
What a Module Contains​
A module can contain any combination of the following:
- Functions
- Cmdlets (compiled in .NET assemblies)
- Scripts (
.ps1files) - Providers
- Variables
- Aliases
- Configuration files
- Resources (JSON, XML, templates, data files)
- Classes
- DSC resources
- Private helper functions
At minimum, a module contains one or more functions packaged into a .psm1 file.
Types of Modules​
PowerShell supports several module types, each suited to different scenarios.
Script Modules (.psm1)​
The most common type. A script module is a PowerShell script file with a file extension of .psm1 instead of .ps1. It contains PowerShell code—usually functions—that are exported when the module is imported.
Manifest Modules (.psd1)​
A manifest is a PowerShell data file containing a hash table. The key-value pairs in the hash table describe the contents and attributes of the module, define prerequisites, and control how the components are processed. Manifests are required to publish a module to the PowerShell Gallery. They enable you to separate your module's implementation from how it loads.
Key manifest settings include:
SettingPurposeModuleVersionVersion number of the moduleGUIDUnique identifier for the moduleAuthorModule author namePowerShellVersionMinimum PowerShell version requiredRequiredModulesModules that must be loaded firstFunctionsToExportFunctions that are exposed to usersCmdletsToExportCmdlets that are exposed to usersAliasesToExportAliases that are exposed to usersPrivateDataAdditional metadata (tags, license URI, project URI)
Binary Modules (.dll)​
Binary modules contain class types that define cmdlets and providers. Unlike script modules, binary modules are written in compiled languages such as C# or VB.NET and compiled into a library (DLL). Binary modules load the fastest because they are compiled ahead of time.
Module Packages (.nupkg)​
Modules packaged for distribution via PowerShellGet (PowerShell Gallery or private repositories). The Microsoft.PowerShell.PSResourceGet module (included with PowerShell 7.4 and later) is the new preferred package manager for PowerShell.
How Modules Work​
When you import a module:
Import-Module MyModule
PowerShell:
- Locates the module in the module path (the
$env:PSModulePathenvironment variable contains a list of folder locations that PowerShell searches recursively for module files) - Reads the module manifest (if present) to determine prerequisites and exported members
- Loads the module into memory
- Makes exported functions available to the session
Module Autoloading​
The first time that you run a command from an installed module, PowerShell automatically imports (loads) that module. This behavior is controlled by the $PSModuleAutoloadingPreference variable.
Default Module Locations​
PowerShell stores modules in the following default locations:
ScopeLocationAll users$Env:ProgramFiles\WindowsPowerShell\ModulesCurrent user$HOME\Documents\WindowsPowerShell\ModulesSystem (shipped with PowerShell)$PSHOME\Modules
These locations are automatically included in the $Env:PSModulePath environment variable.
The Module Folder Structure​
A module must follow a specific folder structure:
MyModule
│
├── MyModule.psm1
├── MyModule.psd1 (optional but recommended)
├── Private (optional)
│ └── Helper.ps1
└── Public (optional)
└── Get-Thing.ps1
The folder name must match the module name.
This structure supports:
- Separation of public and private functions
- Clean organization
- Easier maintenance
Exporting Functions​
By default, all functions in a .psm1 file are exported unless you specify otherwise. Professional modules explicitly control what is exported.
Exporting Functions in a Manifest​
In the module manifest, avoid using wildcards in the FunctionsToExport, CmdletsToExport, and AliasesToExport entries. If the module doesn't export commands of a particular type, specify this explicitly by specifying @(). A missing or $null entry is equivalent to specifying the wildcard *.
Avoid:
FunctionsToExport = '*' # Also avoid omitting the entry entirely
Instead use:
FunctionsToExport = 'Get-ServerInfo', 'New-UserProfile'
CmdletsToExport = @() # Explicit empty array
AliasesToExport = @() # Explicit empty array
Exporting Functions in a Script Module​
Use Export-ModuleMember at the end of the .psm1 file to specify which functions are exposed:
Export-ModuleMember -Function Get-ServerInfo, New-UserProfile
This ensures that only the intended public API is exposed.
Why Modules Are Essential in Professional Environments​
Modules are not just a convenience—they are a requirement for:
- Enterprise automation frameworks
- CI/CD pipelines
- Configuration management
- Reusable toolkits
- Team-based development
- Version-controlled codebases
Scripts alone cannot scale to these environments. Modules provide the structure and discipline needed for long-term maintainability.
Modules vs. Scripts​
FeatureScript (.ps1)Module (.psm1 / .psd1)Executed directlyYesNoLoaded into sessionNoYesReusable across projectsLimitedExcellentSupports versioningNoYesSupports publishingNoYesEncapsulationNoneStrongBest forOne-off tasksReusable automation
Scripts are for doing. Modules are for building.
Practical Example: A Simple Module​
Folder Structure​
MyTools
│
└── MyTools.psm1
MyTools.psm1​
function Get-Greeting {
param([string]$Name)
"Hello, $Name"
}
Export-ModuleMember -Function Get-Greeting
Code explanation: The Get-Greeting function is defined in the script module. Export-ModuleMember -Function Get-Greeting explicitly exports only this function, making it available to users who import the module. Any other functions defined in the module would remain private.
Using the Module​
Import-Module .\MyTools
Get-Greeting -Name "Enrico"
Code explanation: Import-Module .\MyTools loads the module from the current directory. Once loaded, the Get-Greeting function is available in the session.
This is the simplest possible module, but it demonstrates the core concept: packaging reusable functionality.
Summary​
A module is the professional way to package PowerShell code. It provides:
- Organization
- Reusability
- Encapsulation
- Versioning
- Distribution
- Maintainability
Modules elevate PowerShell from a scripting tool to a full automation framework. They are essential for any serious or long-term automation effort, and mastering them is a key step in becoming an advanced PowerShell developer.
Found this helpful? Share the knowledge...
... or support this project to keep it alive!
Previous
Modules & Packaging
Next
Creating Modules
-
The Purpose of a Module
-
What a Module Contains
-
Types of Modules
- Script Modules (
.psm1) - Manifest Modules (
.psd1) - Binary Modules (
.dll) - Module Packages (
.nupkg)
- Script Modules (
-
How Modules Work
- Module Autoloading
- Default Module Locations
-
The Module Folder Structure
-
Exporting Functions
- Exporting Functions in a Manifest
- Exporting Functions in a Script Module
-
Why Modules Are Essential in Professional Environments
-
Modules vs. Scripts
-
Practical Example: A Simple Module
- Folder Structure
- MyTools.psm1
- Using the Module
-
Summary
