PowerShell module

On this page 7

A PowerShell module is a self-contained, reusable package of PowerShell commands, such as cmdlets, functions, aliases, variables and supporting files, that can be loaded into a session as a single unit. In the PowerShell & command line toolset of Windows, modules are the primary way to distribute and organize automation, from built-in administration commands to third-party tools published on the PowerShell Gallery.

Modules give PowerShell its extensibility. Instead of copying scripts between machines, administrators install a module, and its commands become available in every session through automatic module loading. Almost every Windows management area, including networking, storage, Active Directory and Hyper-V, is exposed through dedicated modules.

How a PowerShell module is structured

A module lives in a folder whose name matches the module name, and that folder contains the code file plus optional supporting files. PowerShell discovers modules by searching the directories listed in the PSModulePath environment variable.

The core building blocks are the root module, which holds the code, and the module manifest, a .psd1 data file that describes the module. The manifest records the version, author, minimum PowerShell version, required modules and the commands the module exports.

The table below summarizes the main file types found inside a module folder.

FileExtensionPurpose
Script module file.psm1Contains functions, variables and logic
Module manifest.psd1Declares metadata, version and exports
Binary assembly.dllHolds compiled cmdlets written in C#
Format and type files.ps1xmlControl output display and extend types
Help filesabout_*.help.txt or XMLProvide Get-Help documentation
Files commonly found in a module

Versioned modules can be installed side by side in subfolders named after the version number, such as 2.1.0 and 3.0.0. By default, PowerShell loads the highest available version unless a specific version is requested.

Types of PowerShell modules

PowerShell recognizes four main module types, which differ in how the code is written and loaded. The type affects performance, ease of authoring and the skills a maintainer needs.

Module typeWritten inStrengthTypical use
Script modulePowerShell in a .psm1 fileEasy to write and readInternal admin tooling
Binary moduleCompiled .NET codeFast and strongly typedVendor SDKs and heavy processing
Manifest moduleA .psd1 that wraps other filesCombines several componentsLarger published modules
Dynamic moduleCreated in memory with New-ModuleNo files on diskTemporary or generated code
Module types and their characteristics

Windows also ships CDXML modules, which wrap CIM classes in an XML definition. Many built-in networking and storage cmdlets, including those in the NetAdapter module, are created this way.

Loading, discovery and scope

Since PowerShell 3.0, module autoloading imports a module the first time one of its commands is used, so explicit importing is rarely necessary. Autoloading works only for modules stored in a PSModulePath location; modules elsewhere must be imported by full path.

The most important module cmdlets are listed below with what each one does.

CmdletActionCommon parameter
Get-ModuleLists loaded or available modules-ListAvailable
Import-ModuleLoads a module into the session-RequiredVersion
Remove-ModuleUnloads a module from the session-Name
Install-ModuleDownloads from a repository-Scope CurrentUser
Update-ModuleInstalls a newer version-Name
Core cmdlets for working with modules

A module has its own session state, so variables and helper functions inside it stay private unless they are exported. Authors control the public surface with Export-ModuleMember or the FunctionsToExport field of the manifest; listing commands explicitly is recommended because it speeds up autoloading discovery.

Modules compared with scripts and snap-ins

A module differs from a PowerShell script in purpose: a script runs a task from top to bottom, while a module provides commands that other code calls. Scripts are best for one-off jobs, and modules are best for reusable, versioned functionality.

Modules replaced the older PSSnapin mechanism of Windows PowerShell 1.0, which required registration with an installer and administrator rights. Snap-ins are not supported in PowerShell 7, so legacy snap-ins must be converted to modules. On Windows, PowerShell 7 can still load many Windows PowerShell 5.1 modules through the Windows PowerShell compatibility feature, which runs them in a background session.

Dependencies are declared rather than assumed. A manifest can list RequiredModules that load automatically, and a script can begin with a #Requires -Modules statement so that it stops with a clear error when a needed module or minimum version is missing. This makes automation predictable across servers that may have different module versions installed.

Distribution, trust and common mistakes

Most public modules are distributed through the PowerShell Gallery, a repository accessed with PowerShellGet or its successor, PSResourceGet. Installing with -Scope CurrentUser places the module in the user profile and does not require administrator rights.

Because a module runs code in the user session, trust is essential. Script modules obtained from the internet are subject to the execution policy, and organizations often require modules to be digitally signed before deployment.

SymptomLikely causeFix
Command not foundModule outside PSModulePathMove it or import by path
Old behavior persistsPrevious version still loadedRestart session or Remove-Module
Script cannot be loadedExecution policy blocks itSign it or adjust policy
Function missing after importNot exported by the manifestAdd it to FunctionsToExport
Command name conflictTwo modules export the same nameUse a module-qualified name
Frequent module problems

A frequent design mistake is exporting every helper function, which clutters the session and creates a fragile public interface. Using an approved verb-noun naming pattern, checked with Get-Verb, keeps the module consistent with built-in cmdlets.

In plain words

A PowerShell module is like a toolbox you can add to the command line. Each toolbox holds a set of related tools, such as commands for managing printers or user accounts.

Once the toolbox is installed, its tools are ready whenever they are needed, and PowerShell even opens the box automatically on first use. The key idea is reuse: someone builds the tools once, and many people and computers can use the same tested version.

A real-world example

An IT team at a mid-sized accounting firm repeats the same onboarding steps for about 15 new employees each month: creating the account, adding group memberships, setting a home folder and assigning a license. Each technician used a slightly different script, and mistakes were common.

The team packages the steps as a script module named after the firm, with functions such as New-StaffAccount and Set-StaffHomeFolder, a manifest at version 1.0.0 and comment-based help. They sign it with the internal code signing certificate and publish it to a private file share repository. Technicians install it with Install-Module, and onboarding time drops from about 40 minutes to under 10, with consistent results on every account.