Test-ModuleManifest

Verifies that a module manifest file accurately describes the contents of a module.
Test-ModuleManifest [-Path*] <String> [<CommonParameters>]

The Test-ModuleManifest cmdlet verifies that the files that are listed in the module manifest (.psd1) file are actually in the specified paths.

This cmdlet is designed to help module authors test their manifest files. Module users can also use this cmdlet in scripts and commands to detect errors before they run scripts that depend on the module.

Test-ModuleManifest returns an object that represents the module. This is the same type of object that Get-Module returns. If any files are not in the locations specified in the manifest, the cmdlet also generates an error for each missing file.

Parameters
-Path <String>

  • This value is required
  • Default value is None
  • Accepts pipeline input ByValue

Specifies a path and file name for the manifest file. Enter an optional path and name of the module manifest file that has the .psd1 file name extension. The default location is the current directory. Wildcard characters are supported, but must resolve to a single module manifest file. This parameter is required. You can also pipe a path to Test-ModuleManifest.

<CommonParameters>

This cmdlet supports the common parameters: Verbose, Debug,ErrorAction, ErrorVariable, WarningAction, WarningVariable,OutBuffer, PipelineVariable, and OutVariable.

Inputs

System.String

You can pipe the path to a module manifest to this cmdlet.

Outputs

System.Management.Automation.PSModuleInfo

This cmdlet returns a PSModuleInfo object that represents the module. It returns this object even if the manifest has errors.

Examples
  1. Test a manifest:
    PS C:> test-ModuleManifest -Path "$pshomeModulesTestModule.psd1"
    

    This command tests the TestModule.psd1 module manifest.

  2. Test a manifest by using the pipeline:
    PS C:> "$pshomeModulesTestModule.psd1" | test-modulemanifest
    Test-ModuleManifest : The specified type data file 'C:WindowsSystem32Wi
    ndowsPowerShellv1.0ModulesTestModuleTestTypes.ps1xml' could not be processed because the file was not found. Please correct the path and try again. At line:1 char:34
    + "$pshomeModulesTestModule.psd1" | test-modulemanifest    Name              : TestModule
       Path              : C:Windowssystem32WindowsPowerShellv1.0ModulesTestModuleTestModule.psd1
       Description       : 
       Guid              : 6f0f1387-cd25-4902-b7b4-22cff6aefa7b
       Version           : 1.0
       ModuleBase        : C:Windowssystem32WindowsPowerShellv1.0ModulesTestModule
       ModuleType        : Manifest
       PrivateData       : 
       AccessMode        : ReadWrite
       ExportedAliases   : {}
       ExportedCmdlets   : {}
       ExportedFunctions : {}
       ExportedVariables : {}NestedModules     : {}

    This command uses a pipeline operator (|) to send a path string to Test-ModuleManifest.

    The command output shows that the test failed, because the TestTypes.ps1xml file, which was listed in the manifest, was not found.

  3. Write a function to test a module manifest:
    PS C:> function Test-ManifestBool ($path)
    {$a = dir $path | Test-ModuleManifest -ErrorAction SilentlyContinue $?}
    
       This function is like Test-ModuleManifest, but it returns a Boolean value. The function returns $True if the 
       manifest passed the test and $False otherwise.
       The function uses the Get-ChildItem cmdlet, alias = dir, to get the module manifest specified by the $path 
       variable. The command uses a pipeline operator (|) to pass the file object to Test-ModuleManifest.
       Test-ModuleManifest uses the ErrorAction common parameter with a value of SilentlyContinue to suppress the display 
       of any errors that the command generates. It also saves the PSModuleInfo object that Test-ModuleManifest returns 
       in the $a variable. Therefore, the object is not displayed.
       Then, in a separate command, the function displays the value of the $? automatic variable. If the previous command 
       generates no error, the command displays $True, and $False otherwise.
       You can use this function in conditional statements, such as those that might precede an Import-Module command or 
       a command that uses the module.
Related Links

Export-ModuleMember
Get-Module
Import-Module
New-Module
New-ModuleManifest
Remove-Module