Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create a manifest for nested PowerShell modules

I'm having a minor issue with nested, PowerShell modules.

Get-Module correctly identifies the ExportedCommands, but the ModuleType is listed as Script, rather than Manifest:

PS>get-module

ModuleType Name                      ExportedCommands
---------- ----                      ----------------
Script     Bar                       Get-Bar
Script     Foo                       Get-Foo

Directory structure:

|-Modules
  |-Foobar
    |-Foobar.psd1
    |-Bar
      |-Bar.psm1
    |-Foo
      |-Foo.psm1

Foobar.psd1:

...
# Script module or binary module file associated with this manifest
ModuleToProcess = ''

# Modules to import as nested modules of the module specified in ModuleToProcess
NestedModules = 'Foo\Foo.psm1', 'Bar\Bar.psm1'
...

Have I structured the PSD1 file correctly? In my situation, do I need a dummy/empty Foobar.psm1 file (with corresponding entry in PSD1 file)? Do I need the nested directory structure, or can I just include the two PSM1 files (bar.psm1 and foo.psm1) in the parent directory (Foobar)?

like image 582
craig Avatar asked May 07 '13 16:05

craig


People also ask

How do you create a module manifest in PowerShell?

To create and use a module manifest The best practice to create a module manifest is to use the New-ModuleManifest cmdlet. You can use parameters to specify one or more of the manifest's default keys and values. The only requirement is to name the file.

What is a psd1 file?

File used by Windows PowerShell, a shell program that includes more advanced features than the Windows Command Prompt; contains various configuration information for a PowerShell script or module. PSD1 files are used for storing module manifest information in hash table format.

What cmdlet can you use to build a module manifest?

The New-ModuleManifest cmdlet creates a new module manifest ( . psd1 ) file, populates its values, and saves the manifest file in the specified path. Module authors can use this cmdlet to create a manifest for their module.

How do I automatically install PowerShell modules?

Starting in PowerShell 3.0, installed modules are automatically imported to the session when you use any commands or providers in the module. However, you can still use the Import-Module command to import a module. You can disable automatic module importing using the $PSModuleAutoloadingPreference preference variable.


1 Answers

Directory structure needed to be:

|-Modules
  |-Foobar
    |-Foobar.psd1
    |-Bar.psm1
    |-Foo.psm1

Foobar.psd1 needed to be :

...
# Modules to import as nested modules of the module specified in ModuleToProcess
NestedModules = 'Foo.psm1', 'Bar.psm1'
...
like image 200
craig Avatar answered Sep 30 '22 11:09

craig