Hardware FixRecommendedDevice not working? Your driver may be the problemCheck updates for common hardware issues.Fix DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsSlow PC?RecommendedPC slow today? Run a repair scan before it gets worseResolve common Windows issues and optimize system performance.Scan Now×
Skip to content
World desk3 min

Creating and Using PowerShell Modules: A Practical Guide

Build a reusable PowerShell script module with a .psm1 file, add and validate its manifest, then import, install, or publish it using the right workflow.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

A PowerShell module packages reusable commands so you can load them into a session, share them with a team, or publish them to the PowerShell Gallery. For a simple script module, save functions in a .psm1 file; add a .psd1 manifest to describe the module and validate it before relying on it. Importing a module into a session, installing one from a repository, and publishing one are separate tasks.

What a PowerShell module contains

This walkthrough builds a script module: PowerShell code saved in a .psm1 file. A module can also include supporting files, nested modules, or compiled binary assemblies. Binary modules need a separate build process and may have platform or runtime constraints.

A manifest is a .psd1 data file that describes module metadata and contents; it is not the implementation itself. It can also declare requirements and influence loading. A manifest is optional for a basic local script module, but the PowerShell Gallery requires one for publication.

Create a script module

Create a directory named for the module and place a same-named .psm1 file inside it. For example, the layout for a module called GreetingTools is:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Sale
PowerShell for Sysadmins: Workflow Automation Made Easy
  • Book - powershell for sysadmins: workflow automation made easy
  • Language: english
  • Binding: paperback
GreetingTools/n  GreetingTools.psm1

Save a function in GreetingTools.psm1, for example:

function Get-Greeting {n    param([string]$Name = 'there')n    "Hello, $Name!"n}

That function is the module’s code. The directory-and-file naming pattern also makes the module straightforward to find by name once its parent directory is on PSModulePath.

Add and validate a manifest

For maintainability—and before publishing—create a manifest in the module’s top-level directory with the same module name:

New-ModuleManifest -Path ./GreetingTools/GreetingTools.psd1 -RootModule GreetingTools.psm1 -ModuleVersion '1.0.0' -Author 'Your Name' -Description 'Reusable greeting commands'

New-ModuleManifest creates a starting template. ModuleVersion is the only required manifest key; fields such as author, description, and root module make the package more useful. Review the generated manifest and ensure its RootModule points to the script file. Then validate it:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Test-ModuleManifest -Path ./GreetingTools/GreetingTools.psd1

Fix any reported issues before importing or publishing. A valid manifest helps PowerShell understand the module’s metadata and loading requirements.

Make PowerShell find and import the module

PowerShell discovers modules through directories listed in $env:PSModulePath. Its contents vary by PowerShell edition, operating system, and user or machine configuration, so inspect the current session rather than assuming one installation path:

$env:PSModulePath -split [IO.Path]::PathSeparator

Place the module directory beneath one of the listed locations for name-based discovery. To load it into the current session explicitly, run:

Import-Module GreetingTools

For a one-off local check before installing it in a module search location, import by path instead:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Import-Module ./GreetingTools/GreetingTools.psd1

Importing loads commands into the current session; it does not install the module in a repository or publish it. Windows PowerShell 3.0 and later can also import a module implicitly when you invoke one of its commands, if the module is installed in a discoverable location. Explicit import is useful when you want to load it deliberately before using its commands.

Install a module from a repository

Installing is different from importing: installation obtains a module from a registered repository, while import makes it available in a session. Which installation command is appropriate depends on the PowerShell package-management environment:

Command Use Version context
Install-Module Install a package from a registered repository using PowerShellGet. Availability depends on the installed PowerShellGet environment.
Install-PSResource Install a package from a registered repository using PSResourceGet. Microsoft Learn identifies Microsoft.PowerShell.PSResourceGet as included with PowerShell 7.4 and later and recommends it in that context.

Use the package manager that is available and appropriate for your PowerShell edition and version; these commands are not universal substitutes in every older environment. After installation, import the module if it is not imported automatically.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Publish your module to the PowerShell Gallery

Publishing is for authors sharing a module package; it is not necessary for a local module. The Gallery requires a manifest, so check that it exists, contains the required metadata, and describes the module correctly. Validate it with Test-ModuleManifest before publishing.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  1. Sign in to the PowerShell Gallery and obtain a NuGet API key for your account. Treat this key like a password: do not put a live key in public scripts, source control, or documentation. It can authorize updates to items owned by that account.

  2. From the parent directory containing the module folder, preview the publication with Publish-Module -Path ./GreetingTools -NuGetApiKey $apiKey -WhatIf -Verbose. Replace $apiKey with a securely handled value in your own session.

  3. Review the verbose preview. If the path, package details, and intended destination are correct, run the same command without -WhatIf to publish.

  4. For later releases, update the module version in the manifest before publishing the new package.

    What’s actually slowing this PC down?

    Pick the symptom - the matching free tool is one click away.

    Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

The Gallery publishing workflow uses Publish-Module and a NuGet API key. Keep credentials private, and use the preview to catch path or package mistakes before an actual upload.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

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

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Outdated Drivers Are Slowing You DownFree scan - exact matches
Windows Errors? Fix Them Before They SpreadFree repair scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.