PowerShell Genie

Validate a module manifest

Script 2 min read Windows PowerShell 5.1 and PowerShell 7

Documentation: Microsoft Learn

Get-ChildItem finds every psd1 file under the current directory and ForEach-Object runs Test-ModuleManifest against each full path.

The script

1PS> Get-ChildItem . -Filter *.psd1 -Recurse | ForEach-Object { Test-ModuleManifest $_.FullName | Select-Object Name,Version,PowerShellVersion,CompatiblePSEditions }

Script reader

Inspect before you run

Inspection only

Inspect the script below. It does not run in this browser.

Inspection only — no command has run.

    Show reference output
    1 Name Version PowerShellVersion CompatiblePSEditions
    2 ---- ------- ----------------- --------------------
    3 Contoso.Tools 2.4.0 5.1 {Desktop, Core}
    Inspect this example’s structure

    Read the command and its supplied arguments. This example requires real PowerShell or its module; this diagram does not execute it.

    Get-ChildItem . -Filter *.psd1 -Recurse | ForEach-Object { Test-ModuleManifest $_.FullName | Select-Object Name,Version,PowerShellVersion,CompatiblePSEditions }
    1. Stage 1Get-ChildItem-Filter -Recurse
    2. Stage 2ForEach-ObjectPositional values or no named parameters

      How it works

      Get-ChildItem finds every psd1 file under the current directory and ForEach-Object runs Test-ModuleManifest against each full path. The projection reports the module name and version alongside the required PowerShell version and the editions the manifest claims to support.

      Adapting it

      Assert the reported version against the build number and throw when they diverge, which turns an informational listing into a gate that stops a bad release.

      If the result is unexpected

      A module manifest fails validation on another host.

      Referenced files, dependency versions and compatible editions may differ from the development machine.

      1. Run validation from the packaged module location and inspect the first reported dependency or path failure.

      Validate the result

      The packaged manifest validates with its actual files and supported runtime.

      Keep the check reliable

      Validate the packaged artifact in the target runtime in addition to validating the source folder.

      Primary documentation

      Get-ChildItem reference

      Continue
      Genie guideValidate a module manifest

      Get-ChildItem finds every psd1 file under the current directory and ForEach-Object runs Test-ModuleManifest against each full path.