---
title: PowerShell Modules
tags: [powershell, modules, package-management, scripting]
---

# PowerShell Modules

Modules are packages that contain PowerShell members, such as cmdlets, providers, functions, variables, and aliases. They allow you to organize your code and share it with others.

**Parent Topic:** [[programming/PowerShell/Scripting|PowerShell Scripting and Programming]]
**Related:** [[programming/PowerShell/PowerShell|PowerShell Comprehensive Guide]]

## 1. Using Modules

### Finding and Installing
The PowerShell Gallery is the central repository for PowerShell content.

```powershell
# Find a module
Find-Module -Name "PSReadLine"

# Install a module (scope CurrentUser is recommended for non-admins)
Install-Module -Name "PSReadLine" -Scope CurrentUser
```

### Importing and Listing
PowerShell usually imports installed modules automatically when you use a command from them. However, you can manage them manually.

```powershell
# List loaded modules
Get-Module

# List all available modules on disk
Get-Module -ListAvailable

# Manually import a module
Import-Module -Name "ActiveDirectory"
```

## 2. Creating a Module

A module is essentially a PowerShell script saved with a `.psm1` extension.

### Step 1: Create the Script Module (.psm1)
Create a file named `MyTools.psm1`.

```powershell
# MyTools.psm1

function Get-Hello {
    param($Name)
    return "Hello, $Name"
}

function Get-Goodbye {
    param($Name)
    return "Goodbye, $Name"
}

# Export specific functions to be visible to the user
Export-ModuleMember -Function Get-Hello, Get-Goodbye
```

### Step 2: Import Your Module
```powershell
Import-Module .\MyTools.psm1
Get-Hello -Name "World"
```

## 3. Module Manifests (.psd1)

A manifest is a hash table that describes the module (version, author, dependencies). It is required for publishing to the Gallery.

```powershell
# Generate a manifest file
New-ModuleManifest -Path .\MyTools.psd1 -RootModule .\MyTools.psm1 -Author "Your Name" -Description "My custom tools"
```

---
Return to [[programming/PowerShell/Scripting|PowerShell Scripting and Programming]]