PowerShell Module Manifests
A module manifest is a data file that describes a module. It names the module's files, its version, and its author.
Create a manifest and read it back
The manifest is built beside its module file. Reading it back shows the same values that were written into it.
$root = $PSScriptRoot
Set-Content -Path (Join-Path $root "DemoTool.psm1") -Value 'function Get-DemoGreeting { "hello" }'
New-ModuleManifest -Path (Join-Path $root "DemoTool.psd1") -RootModule "DemoTool.psm1" -ModuleVersion "1.0.0" -Author "Ana" -Description "Demo module"
$data = Import-PowerShellDataFile -Path (Join-Path $root "DemoTool.psd1")
$data.RootModule
$data.ModuleVersion
$data.AuthorCheck a manifest with Test-ModuleManifest
The check loads the manifest and reports its name, version, and author. All three match the values from the first snippet.
$root = $PSScriptRoot
Set-Content -Path (Join-Path $root "DemoTool.psm1") -Value 'function Get-DemoGreeting { "hello" }'
New-ModuleManifest -Path (Join-Path $root "DemoTool.psd1") -RootModule "DemoTool.psm1" -ModuleVersion "1.0.0" -Author "Ana" -Description "Demo module"
$module = Test-ModuleManifest -Path (Join-Path $root "DemoTool.psd1")
$module.Name
$module.Version.ToString()
$module.AuthorThe manifest sits beside its module file
Both files share the module name. Listing them in name order shows the manifest first and the module file second.
$root = $PSScriptRoot
Set-Content -Path (Join-Path $root "DemoTool.psm1") -Value 'function Get-DemoGreeting { "hello" }'
New-ModuleManifest -Path (Join-Path $root "DemoTool.psd1") -RootModule "DemoTool.psm1" -ModuleVersion "1.0.0" -Author "Ana" -Description "Demo module"
Get-ChildItem -Path $root -Filter "DemoTool.*" | Sort-Object Name | Select-Object -ExpandProperty NameExample
$root = $PSScriptRoot
Set-Content -Path (Join-Path $root "DemoTool.psm1") -Value 'function Get-DemoGreeting { "hello" }'
New-ModuleManifest -Path (Join-Path $root "DemoTool.psd1") -RootModule "DemoTool.psm1" -ModuleVersion "1.0.0" -Author "Ana" -Description "Demo module"
$data = Import-PowerShellDataFile -Path (Join-Path $root "DemoTool.psd1")
"Root: " + $data.RootModule
"Version: " + $data.ModuleVersion
"Author: " + $data.Author
$checked = Test-ModuleManifest -Path (Join-Path $root "DemoTool.psd1")
"Checked name: " + $checked.NameKey points
- Manifest: a .psd1 file that describes a module.
- Use New-ModuleManifest to create a manifest file.
- RootModule: the manifest setting that names the module's main script file.
- ModuleVersion: the manifest setting that holds the module's version number.
- Author: the manifest setting that names the person who wrote the module.
- Use Import-PowerShellDataFile to read a manifest back as data.
In this example, the module file and its manifest are built together, and the manifest is read back as data. The check then confirms the manifest loads and reports the same module name.
Note
Test-ModuleManifest checks that a manifest loads, and it reports the same name, version, and author.
Try it Yourself
Edit the code, then press Run.
Running is simulated
Exercise
Which command creates a new module manifest file?