Author Posts

March 24, 2016 at 3:03 am

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.

March 24, 2016 at 3:55 am

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).

March 24, 2016 at 3:59 am

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

March 24, 2016 at 4:00 am

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.

March 24, 2016 at 4:03 am

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.

March 24, 2016 at 6:25 am

Version property of module is 1.0.