Modules and the PowerShell Gallery

By the end of this lesson you'll load and discover modules, pull ready-made tools from the PowerShell Gallery with Find-Module and Install-Module, understand where PowerShell looks for modules, and package your own functions into a reusable .psm1 with a .psd1 manifest — turning loose scripts into shareable tools.

Learn Modules and the PowerShell Gallery in our free PowerShell course — an interactive lesson with worked examples, a practice exercise and a quick reference.

Part of the free Powershell course at LearnCodingFast — hands-on lessons with examples you run in your browser, plus practice exercises and a quick quiz.

A module is an app on your phone . The PowerShell Gallery is the app store: you Find-Module to browse, Install-Module to download, and Update-Module to upgrade. Once installed, the app's features appear automatically when you reach for them (that's auto-loading via $env:PSModulePath ). And when you build something useful, you can package it like an app developer: a .psm1 holds the code, a .psd1 manifest is the "store listing" (name, version, author), and Export-ModuleMember decides which buttons are public.

1. Loading & Discovering Modules

A module bundles related commands into one reusable package. Get-Module shows what's loaded; add -ListAvailable to see everything installed. Import-Module loads one into your session, and Get-Command -Module <name> lists exactly what it provides. Read this worked example, then run it.

2. The PowerShell Gallery

The PowerShell Gallery is the official public repository of community and Microsoft modules. Find-Module searches it without installing anything, Install-Module downloads and installs (use -Scope CurrentUser when you're not an administrator), and Update-Module upgrades to the latest version. Installed modules live on $env:PSModulePath , which is why PowerShell can auto-load them the moment you call one of their commands.

Now you try. Fill in the three blanks using the hints in the comments, then run it.

3. Authoring Your Own Module

Turning your functions into a module is straightforward. Put the code in a .psm1 file, then call Export-ModuleMember to declare which functions are public (anything you don't export stays a private helper). Describe the module with a .psd1 manifest — a metadata file holding the version, author, RootModule, and exported members — which you can scaffold with New-ModuleManifest .

List your exports explicitly in the manifest's FunctionsToExport (and use Export-ModuleMember in the .psm1 ) rather than relying on the * wildcard. Explicit exports load faster — PowerShell can read the manifest without executing the whole module — and they keep private helpers truly private.

To make a module auto-load like a Gallery one, drop its folder (named the same as the module) into any directory on $env:PSModulePath — most commonly your Documents\PowerShell\Modules folder. Then any command it exports just works, no Import-Module required.

The folder name, the .psm1 base name, and the manifest base name should all match the module name so auto-loading can find it.

No blanks this time — just a brief and an outline to keep you on track. Build it, run it, and check your output against the example in the comments. Packaging functions into a reusable module is the leap from "scripts" to "tools".

Practice quiz

What is a PowerShell module?

  • A reusable package of related cmdlets, functions, and variables
  • A type of error
  • A keyboard shortcut
  • A single one-line command

Answer: A reusable package of related cmdlets, functions, and variables. A module bundles related commands and resources so they can be shared and reused as one unit.

Which cmdlet loads a module into the current session?

  • Add-Module
  • Use-Module
  • Import-Module
  • Load-Module

Answer: Import-Module. Import-Module makes a module's commands available in the current session.

Which cmdlet lists the modules currently imported?

  • List-Module
  • Get-Module
  • Find-Module
  • Show-Module

Answer: Get-Module. Get-Module lists loaded modules; add -ListAvailable to see installed but not-yet-loaded ones.

Which cmdlet searches the PowerShell Gallery for a module?

  • Search-Module
  • Get-Module
  • Import-Module
  • Find-Module

Answer: Find-Module. Find-Module queries the online PowerShell Gallery without installing anything.

Which cmdlet downloads and installs a module from the Gallery?

  • Install-Module
  • Get-Module
  • Save-Module
  • Add-Module

Answer: Install-Module. Install-Module downloads a module from the PowerShell Gallery and installs it locally.

What does $env:PSModulePath contain?

  • A list of cmdlets
  • The folders PowerShell searches for modules
  • Your command history
  • Installed Gallery versions

Answer: The folders PowerShell searches for modules. PSModulePath is a semicolon-separated list of directories where PowerShell looks for modules to auto-load.

Which file extension holds a script module's code?

  • A .dll file
  • A .ps1xml file
  • A .json file
  • A .psm1 file

Answer: A .psm1 file. Script modules live in a .psm1 file; a .psd1 manifest describes the module's metadata.

What is the purpose of a .psd1 module manifest?

  • It installs dependencies at runtime
  • It stores the actual function code
  • It describes metadata like version, author, and exports
  • It logs errors

Answer: It describes metadata like version, author, and exports. The .psd1 manifest declares the module's version, author, dependencies, and which members it exports.

Inside a .psm1, which command controls what the module exports?

  • Show-Module
  • Export-ModuleMember
  • Set-Export
  • Publish-Member

Answer: Export-ModuleMember. Export-ModuleMember explicitly declares which functions, variables, and aliases the module makes public.

How do you list the commands provided by a specific module?

  • Get-Command -Module <name>
  • Get-Module -Commands
  • Show-Command <name>
  • Find-Module -Commands

Answer: Get-Command -Module <name>. Get-Command -Module <name> lists every command exported by that module.