Alexander Schmidt
Alexander Schmidt

Reputation: 5723

PowerShell custom module manifest does not expose functions declared

I've created a PowerShell module. The module exposes 3 functions. When I install it without a manifest directly the output will be:

> Import-Module AzureDD
> Get-Module | Where { $_.Name -eq 'AzureDD' }

ModuleType Version    Name                                ExportedCommands
---------- -------    ----                                ----------------
Script     0.0        AzureDD                             {New-AzureDDAppPermission, New-AzureDDAppRegistration, Sync-AzureDDStorageContainer}

This works because my last line in the psm file is:

Export-ModuleMember -Function New-AzureDDAppRegistration, New-AzureDDAppPermission, Sync-AzureDDStorageContainer

Now I wanted to add versionning and more meta data and went on with

> New-ModuleManifest -Path .\AzureDD.psd1 -ModuleVersion "2.0"

which creates a new file AzuerDD.psd1. In here I edited a lot of stuff. Besides other changes I also defined the exported functions as follows:

FunctionsToExport = @('New-AzureDDAppPermission', 'New-AzureDDAppRegistration', 'Sync-AzStorageContainer')

I can test this successfully:

> Test-ModuleManifest .\AzureDD.psd1

ModuleType Version    Name                                ExportedCommands
---------- -------    ----                                ----------------
Manifest   2.0        AzureDD                             {New-AzureDDAppPermission, New-AzureDDAppRegistration, Sync-AzStorageContainer}

But when I actually import this it will not show any exported command:

> Import-Module .\AzureDD.psd1
> Get-Module | Where { $_.Name -eq 'AzureDD' }

ModuleType Version    Name                                ExportedCommands
---------- -------    ----                                ----------------
Manifest   2.0        AzureDD

See how it changed to Manifest compared to my very first snippet! I've ensured that I did Remove-Module AzureDD -Force all the time before I re-imported it.

Upvotes: 0

Views: 825

Answers (1)

Mathias R. Jessen
Mathias R. Jessen

Reputation: 174455

FunctionsToExport is like a sieve - it just allows nested modules to export their functions via the manifest, but they still have to be defined somewhere.

Make sure the script module (the .psm1 file) is specified as the RootModule (or at least a NestedModule) in the manifest:

@{
  # Script module or binary module file associated with this manifest.
  RootModule = 'AzureDD.psm1'

  # ...
}

Upvotes: 3

Related Questions