Share this post: This is part of an ongoing blog series by Adam Gordon. Adam will guide you through a PowerShell command each week, explaining when and how to use them. This week Adam will be covering New-ModuleManifest.
When should you use New-ModuleManifest
The New-ModuleManifest cmdlet creates an empty module manifest (.psd1), populates it with values, and saves it in the specified path.
This cmdlet can be used by module authors to create a module manifest. A module manifest is a file in.psd1 that contains a hashtable. The module’s contents and attributes are described in the module’s hash table. They also define the prerequisites and determine how the modules will be processed. Modules do not require manifests.
New-ModuleManifest creates an output that contains all commonly used manifest keys. You can use the default output to create a template for your manifest. Open the resulting file with a text editor to modify or add values or module keys that this cmdlet doesn’t add.
Except for -Path, -PassThru, each parameter creates a module key and its value. Only the ModuleVersion key is required in a module manifest. Except as specified in the parameter description (which is not required), New-ModuleManifest creates an empty comment string for the associated value.
PowerShell 2.0’s New-ModuleManifest prompts for the values of common parameters that are not specified in a command. New-ModuleManifest is only available in PowerShell 3.0.
The manifest must contain certain values if you plan to publish your module in PowerShell Gallery.
What version of PowerShell do I use?
Get the PowerShell Version for your machine
$PSVersionTable
This command displays the PowerShell version information for your machine.
How to use the New-ModuleManifest
Create a new module-specific manifest:
New-ModuleManifest -Path C:\PShellTest\Test-Module.psd1 -PassThru
This example creates a module manifest in the file specified by the path parameter. The -PassThru parameter transmits the output to both the pipeline and the file.
The output shows all default values for all keys in the manifest.
Create a new manifest using some prepopulated settings
New-ModuleManifest -PowerShellVersion 1.0 -AliasesToExport JKBC, DRC, TAC -Path C:\PShellTest\ManifestTest.psd1
This example creates a module manifest. It adds values to the respective manifest keys using the -PowerShellVersion or -AliasesToExport parameters.
Make a manifest that includes other modules
$moduleSettings = @RequiredModules = (“BitsTransfer”, @ModuleName=”PSScheduledJob”ModuleVersion=”1.0.0.0”;GUID=”50cdb55f-5ab7-489f-9e94-4ec21ff51e59”)Path = ‘C:\PShellTest\ManifestTest2.psd1’
New-ModuleManifest @moduleSettings
This example uses a string format for the BitsTransfer module’s name and a hash table format for the name, GUID and version of the PSScheduledJob Module.
This example shows you how to use the string- and hash-table formats of the –ModuleList, requiredModules and –NestedModules parameters. You can combine strings with hash tables within the same parameter value.
Make a manifest that allows for the provision of updated help
$moduleSettings = @/span>HelpInfoUri = ‘http://https://go.microsoft.com/fwlink/?LinkID=603’Path = ‘C:\PShellTest\ManifestTest3.psd1’
New-ModuleManifest @moduleSettings
This example uses a -HelpInfoUri parameter in order to create a HelpInfoUri Key in the module manifest. The key and parameter values must start with http or https. This value tells Updatable Help where to find the HelpInfo XML module-specific help information file.
Information about the module:
Get-Module Microsoft.PowerShell.Diagnostics -List | Format-List -Property *
This example shows you how to get the configuration value of a module. The module manifest values are reflected in module object properties.
The Get-Module cmdlet is used to get the Microsoft.PowerShell.Diagnostics module using the -List parameter. This command sends the module to Format-List cmdlet, which displays all properties and values for the object.
Learn the command from last week: New-Module.
Do you need PowerShell training? ITProTV offers PowerShell online IT training courses.