#7495·PowerShell

Test-ModuleManifest checks if a required module is installed but doesn't check version

Author: rjmholtCreated Aug 10, 2018Updated Sep 16, 2026
LabelsIssue-BugWG-CmdletsUp-for-GrabsWG-Reviewed

Test-ModuleManifest will fail if a RequiredModule is not installed on the current machine.

I went and looked at the source out of curiosity, and although we do check, we ignore the other constraints on the module: https://github.com/PowerShell/PowerShell/blob/1243891ea8c04609ce21d0b31d40945fd46a3576/src/System.Management.Automation/engine/Modules/TestModuleManifestCommand.cs#L192-L207

It seems like we should:

  1. Commit to doing a full check of the required modules' constraints, since we're already checking they are installed
  2. Give a better error message when a module isn't installed; it currently just says something like:
    Test-ModuleManifest : The specified RequiredModules entry 'banana' in the module manifest '/home/rob/Documents/Dev/sandbox/AModule/AModule.psd1' is invalid. Try again after updating this entry with valid values.       
    At line:1 char:1        
    + Test-ModuleManifest ./AModule.psd1
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (./AModule.psd1:String) [Test-ModuleManifest], DirectoryNotFoundException
    + FullyQualifiedErrorId : Modules_InvalidRequiredModulesinModuleManifest,Microsoft.PowerShell.Commands.TestModuleManifestCommand
    
  3. Provide an option to only check the validity of the manifest itself, and not whether it will work in the current session (this last point I think is part of the need to separate "Module manifests that are not well-formed" from "Module manifests that cannot be loaded in the current session"

Steps to reproduce

> New-ModuleManifest -Path ./AModule.psd1 -RequiredModules @{
ModuleName = 'Microsoft.PowerShell.Utility'
ModuleVersion = '100.0'
}
> Test-ModuleManifest ./AModule.psd1

Expected behavior

<Error message about not having the required version>

Actual behavior


ModuleType Version    Name                                ExportedCommands
---------- -------    ----                                ----------------
Manifest   0.0.1      AModule                             

Environment data

> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      6.1.0-preview.2
PSEdition                      Core
GitCommitId                    v6.1.0-preview.2
OS                             Linux 4.15.0-30-generic #32-Ubuntu SMP Thu Jul 26 17:42:43 UTC 2018
Platform                       Unix
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0