Creating PowerShell Module Manifests with New-ModuleManifest
Welcome back to Wahmans PowerShell blog! Today, we’re diving into New-ModuleManifest
— a powerful cmdlet used to define and manage metadata for PowerShell modules. If you’re working on modularizing your PowerShell scripts, understanding this cmdlet is essential.
New-ModuleManifest
is used to create a module manifest file (.psd1) that defines key configuration details about your PowerShell module. This includes information such as versioning, author, dependencies, exported functions, and more. It’s the heart of any well-structured PowerShell module.
Usage Syntax
New-ModuleManifest [-Path] <String> [-RootModule <String>] [-ModuleVersion <Version>] [...additional parameters...]
Example 1: Basic Manifest Creation (Beginner)
This basic example creates a module manifest for a simple module with minimal metadata set.
New-ModuleManifest -Path 'C:\Modules\SimpleModule\SimpleModule.psd1' -RootModule 'SimpleModule.psm1' -ModuleVersion '1.0.0'
This will create a SimpleModule.psd1
file in the given directory which you can then edit or extend as needed.
Example 2: Including Author and Description (Intermediate)
Let’s add more detail including the author, description, and company information.
New-ModuleManifest -Path 'C:\Modules\InfoModule\InfoModule.psd1' \
-RootModule 'InfoModule.psm1' \
-ModuleVersion '1.0.0' \
-Author 'Johan Wahman' \
-CompanyName 'WahmanTech' \
-Description 'A module that provides information display utilities'
These additional fields help users understand your module’s purpose and authorship.
Example 3: Exporting Functions and Cmdlets (Advanced)
If your module only exports specific functions, define them explicitly in your manifest.
New-ModuleManifest -Path 'C:\Modules\FuncModule\FuncModule.psd1' \
-RootModule 'FuncModule.psm1' \
-ModuleVersion '2.1.0' \
-Author 'Johan Wahman' \
-FunctionsToExport 'Get-Status','Show-Info' \
-CmdletsToExport 'Invoke-Check'
This ensures only the specific functions or cmdlets you list are made available when someone imports your module.
Example 4: Full Feature Template with Dependencies (Expert)
Building a production-ready module? Include dependencies, required PowerShell version, and tags.
New-ModuleManifest -Path 'C:\Modules\AdvancedModule\AdvancedModule.psd1' \
-RootModule 'AdvancedModule.psm1' \
-ModuleVersion '3.0.0' \
-Author 'Johan Wahman' \
-CompanyName 'WahmanTech Pro' \
-Description 'An advanced module used for enterprise deployments' \
-PowerShellVersion '5.1' \
-RequiredModules 'PSReadLine', 'PSScriptAnalyzer' \
-Tags 'enterprise','deployment','advanced-module'
This sets a strong foundation for creating highly modular and reusable PowerShell code across systems and teams.
Wrap-up
Understanding and effectively using New-ModuleManifest
elevates the structure and maintainability of your PowerShell modules. Whether you’re a beginner or managing large-scale script libraries, this cmdlet helps you scale your scripting practices efficiently.
Happy scripting, and I will see you in the next post!
Leave a Reply