Get-Module list module manifest .psd1 file

Hi, having written PowerShell module with bunch of advanced functions next step was to create module manifest.

$manifestParams = @{
Author = “Bojan Živković”
CompanyName = “My Company”
RootModule = “.\Tools.psm1”
Path = “Tools.psd1”

              New-ModuleManifest @manifestParams

I played with FunctionsToExport and loading of .psd1 worked well. However I noticed in Path property of a module there was a path to .psm1 file instead of .psd1 file. For instance path for built-in module Microsoft.PowerShell.Utility points to .psd1 file. This does not affect functionality but still I want to know how to check whether module manifest exists for some module since there is no cmdlet Get-ModuleManifest.

One way would be to check the Version property, when no PSD1 file is present it defaults to 0.0 while a Module Manifest has a default version of 1.0

Alternatively when there is no manifest the GUID defaults to 00000000-0000-0000-0000-000000000000

Actually the best check might be the RootModule which is blank when there is no manifest but (AFAIK) should always be present in a manifest (EDIT: as Dave pointed out below modules may be listed under NestedModules so you would need to check that too).

You can test for a module manifest by looking for (ModuleName).psd1 in the folder that’s found on the ModuleBase property of the object returned by Get-Module:

function Test-ModuleHasManifest([string] $ModuleName)
    $module = Get-Module $ModuleName -ListAvailable | Select-Object -First 1
    if ($null -eq $module) { return $false }
    $manifestPath = Join-Path $module.ModuleBase "$ModuleName.psd1"

    return Test-Path -LiteralPath $manifestPath -Leaf

Incidentally, those built-in modules that show up as type “Manifest” have no RootModule. Instead, they load up everything else with NestedModules in the manifest, which slightly changes the output of Get-Module.

Ah, so if checking for RootModule you would also need to check NestedModules. Still probably the most reliable means without manually checking the file exists.

Version property of module is 1.0.