Skip to content

Latest commit

 

History

History

v2-Manifest-RootModule-is-not-supported

v2 does not support the manifest field RootModule

The manifest field RootModule was introduced in PowerShell v3 instead of ModuleToProcess. A manifest generated by New-ModuleManifest suggests RootModule. If it is used then in PowerShell v2 Import-Module fails.

Thus, if the module target version includes PowerShell v2 then the suggested manifest field RootModule should be replaced with old ModuleToProcess.

help New-ModuleManifest -Parameter RootModule

    -RootModule <String>
        ...
        Note: In Windows PowerShell 2.0, this key was called "ModuleToProcess."
        You can use the "RootModule" parameter name or its "ModuleToProcess"
        alias.

There is a reason to use the obsolete ModuleToProcess even if a module is not for v2. From this discussion:

If a user using v2 tries to load a module that uses RootModule in the manifest, PowerShell gives them an unintuitive error about invalid manifest property. If a user using v2 tries to load a module that requires v3+ that uses ModuleToProcess, they get an error that indicates the module requires v3+.

Scripts

  • Test1.ps1 imports Test1.psd1 which uses the new field RootModule. It fails in PowerShell v2 and works in v3+.
  • Test2.ps1 imports Test2.psd1 which uses the old field ModuleToProcess. It works in PowerShell v2+.
  • Test3.ps1 imports Test3.psd1 which uses the new field RootModule and specifies PowerShellVersion='3.0'. In PowerShell v2 it fails with an unintuitive message.
  • Test4.ps1 imports Test4.psd1 which uses the old field ModuleToProcess and specifies PowerShellVersion='3.0'. In PowerShell v2 it fails with a clear message.