0
0
PowerShellscripting~5 mins

Module manifest (.psd1) in PowerShell

Choose your learning style9 modes available
Introduction

A module manifest (.psd1) is a file that describes important details about a PowerShell module. It helps PowerShell know what the module contains and how to use it.

When you create a PowerShell module and want to share it with others.
When you want to specify which scripts, functions, or commands are part of your module.
When you want to add version info, author name, or required PowerShell version to your module.
When you want to control what users can see or use inside your module.
When you want to include additional files like help documents or scripts with your module.
Syntax
PowerShell
@{
    ModuleVersion = '1.0'
    GUID = 'unique-guid-here'
    Author = 'Your Name'
    Description = 'What this module does'
    FunctionsToExport = @('Function1', 'Function2')
    CmdletsToExport = @()
    VariablesToExport = @()
    AliasesToExport = @()
    NestedModules = @()
    RequiredModules = @()
    PowerShellVersion = '7.0'
}

The manifest is a hashtable inside a .psd1 file.

Each key describes a part of the module, like version or exported functions.

Examples
This manifest defines a simple module with one function exported.
PowerShell
@{
    ModuleVersion = '1.0'
    GUID = '12345678-1234-1234-1234-123456789abc'
    Author = 'Alice'
    Description = 'Sample module'
    FunctionsToExport = @('Get-Info')
    PowerShellVersion = '5.1'
}
This manifest shows a module that requires another module and exports two functions.
PowerShell
@{
    ModuleVersion = '2.0'
    GUID = '87654321-4321-4321-4321-cba987654321'
    Author = 'Bob'
    Description = 'Advanced tools'
    FunctionsToExport = @('Start-Task', 'Stop-Task')
    RequiredModules = @('PSReadLine')
    PowerShellVersion = '7.2'
}
Sample Program

This script creates a module manifest file, saves it, shows its content, defines a function, imports the module, and calls the function.

PowerShell
# Create a simple module manifest file
$manifest = @{
    ModuleVersion = '1.0'
    GUID = '11111111-2222-3333-4444-555555555555'
    Author = 'Jane Doe'
    Description = 'Demo module manifest'
    FunctionsToExport = @('SayHello')
    PowerShellVersion = '7.0'
}

# Save the manifest to a file
$manifestPath = 'DemoModule.psd1'
$manifest | Out-File -FilePath $manifestPath -Encoding UTF8

# Show the content of the manifest file
Get-Content $manifestPath

# Define the function to export
function SayHello {
    Write-Output 'Hello from the module!'
}

# Import the module using the manifest
Import-Module -Name .\DemoModule

# Call the exported function
SayHello
OutputSuccess
Important Notes

The GUID should be unique for each module. You can generate one using New-Guid.

FunctionsToExport controls which functions are visible when the module is imported.

Always save the manifest file with the .psd1 extension in the module folder.

Summary

A module manifest (.psd1) describes your PowerShell module's details.

It controls what parts of the module are visible and required.

Creating a manifest helps others use your module easily and correctly.