Skip to content

Commit 32c7ed5

Browse files
markroloffsdwheeler
authored andcommitted
Updates to module manifest how-to (#4912)
* Update module manifest how-to Updated example template * Update module manifest how-to Update manifest elements table to better reflect current default manifest properties and usage. Replaced reference to editing with ISE with VS Code. * Update how-to-write-a-powershell-module-manifest.md
1 parent 7912457 commit 32c7ed5

File tree

1 file changed

+52
-25
lines changed

1 file changed

+52
-25
lines changed

developer/module/how-to-write-a-powershell-module-manifest.md

Lines changed: 52 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ For simple modules that contain only a single .psm1 or binary assembly, a module
3535

3636
2. Add in any additional elements to the manifest that you want to have in the file.
3737

38-
Generally speaking, this will probably be done in whatever text editor you prefer, such as Notepad. However this technically is a script file that contains code, so you may wish to edit it in an actual scripting or development environment, such as the PowerShell ISE. Again, note that all elements of a manifest file are optional, except for the ModuleVersion number.
38+
Generally speaking, this will probably be done in whatever text editor you prefer, such as Notepad. However this technically is a script file that contains code, so you may wish to edit it in an actual scripting or development environment, such as Visual Studio Code. Again, note that all elements of a manifest file are optional, except for the ModuleVersion number.
3939

4040
For descriptions of the keys and values you can have in a module manifest, see the **Module Manifest Elements** below. For additional information, see the parameter descriptions in the [New-ModuleManifest](/powershell/module/Microsoft.PowerShell.Core/New-ModuleManifest) cmdlet.
4141

@@ -77,16 +77,16 @@ The following table describes the elements you can have in a module manifest
7777
|RequiredModules<br /><br /> Type: [string[]]|@()|Modules that must be imported into the global environment prior to importing this module. This will load any modules listed unless they have already been loaded. (For example, some modules may already be loaded by a different module.). It is also possible to specify a specific version to load using `RequiredVersion` rather than `ModuleVersion`. When using `ModuleVersion` it will load the newest version available with a minimum of the version specified.<br /><br /> Example: `RequiredModules = @(@{ModuleName="myDependentModule"; ModuleVersion="2.0"; Guid="cfc45206-1e49-459d-a8ad-5b571ef94857"})`<br /><br /> Example: `RequiredModules = @(@{ModuleName="myDependentModule"; RequiredVersion="1.5"; Guid="cfc45206-1e49-459d-a8ad-5b571ef94857"})`|
7878
|RequiredAssemblies<br /><br /> Type: [string[]]|@()|Assemblies that must be loaded prior to importing this module.<br /><br /> Note that unlike RequiredModules, PowerShell will load the RequiredAssemblies if they are not already loaded.|
7979
|ScriptsToProcess<br /><br /> Type: [string[]]|@()|Script (.ps1) files that are run in the caller's session state when the module is imported. This could be the global session state or, for nested modules, the session state of another module. You can use these scripts to prepare an environment just as you might use a login script.<br /><br /> These scripts are run before any of the modules listed in the manifest are loaded.|
80-
|TypesToProcess<br /><br /> Type: [Object[]]|@()|Type files (.ps1xml) to be loaded when importing this module.|
81-
|FormatsToProcess<br /><br /> Type: [Object[]]|@()|Format files (.ps1xml) to be loaded when importing this module.|
82-
|NestedModules<br /><br /> Type: [Object[]]|@()|Modules to import as nested modules of the module specified in RootModule/ModuleToProcess.<br /><br /> Adding a module name to this element is similar to calling `Import-Module` from within your script or assembly code. The main difference is that it's easier to see what you are loading here in the manifest file. Also, if a module fails to load here, you will not yet have loaded your actual module.<br /><br /> In addition to other modules, you may also load script (.ps1) files here. These files will execute in the context of the root module. (This is equivalent to dot sourcing the script in your root module.)|
83-
|FunctionsToExport<br /><br /> Type: String|'*'|Specifies the functions that the module exports (wildcard characters are permitted) to the caller's session state. By default, all functions are exported. You can use this key to restrict the functions that are exported by the module.<br /><br /> The caller's session state can be the global session state or, for nested modules, the session state of another module. When chaining nested modules, all functions that are exported by a nested module will be exported to the global session state unless a module in the chain restricts the function by using the FunctionsToExport key.<br /><br /> If the manifest also exports aliases for the functions, this key can remove functions whose aliases are listed in the AliasesToExport key, but this key cannot add function aliases to the list.|
84-
|CmdletsToExport<br /><br /> Type: String|'*'|Specifies the cmdlets that the module exports (wildcard characters are permitted). By default, all cmdlets are exported. You can use this key to restrict the cmdlets that are exported by the module.<br /><br /> The caller's session state can be the global session state or, for nested modules, the session state of another module. When you are chaining nested modules, all cmdlets that are exported by a nested module will be ultimately exported to the global session state unless a module in the chain restricts the cmdlet by using the CmdletsToExport key.<br /><br /> If the manifest also exports aliases for the cmdlets, this key can remove cmdlets whose aliases are listed in the AliasesToExport key, but this key cannot add cmdlet aliases to the list.|
85-
|VariablesToExport<br /><br /> Type: String|'*'|Specifies the variables that the module exports (wildcard characters are permitted) to the caller's session state. By default, all variables are exported. You can use this key to restrict the variables that are exported by the module.<br /><br /> The caller's session state can be the global session state or, for nested modules, the session state of another module. When you are chaining nested modules, all variables that are exported by a nested module will be exported to the global session state unless a module in the chain restricts the variable by using the VariablesToExport key.<br /><br /> If the manifest also exports aliases for the variables, this key can remove variables whose aliases are listed in the AliasesToExport key, but this key cannot add variable aliases to the list.|
86-
|AliasesToExport<br /><br /> Type: String|'*'|Specifies the aliases that the module exports (wildcard characters are permitted) to the caller's session state. By default, all aliases are exported. You can use this key to restrict the aliases that are exported by the module.<br /><br /> The caller's session state can be the global session state or, for nested modules, the session state of another module. When you are chaining nested modules, all aliases that are exported by a nested module will be ultimately exported to the global session state unless a module in the chain restricts the alias by using the AliasesToExport key.|
80+
|TypesToProcess<br /><br /> Type: [string[]]|@()|Type files (.ps1xml) to be loaded when importing this module.|
81+
|FormatsToProcess<br /><br /> Type: [string[]]|@()|Format files (.ps1xml) to be loaded when importing this module.|
82+
|NestedModules<br /><br /> Type: [string[]]|@()|Modules to import as nested modules of the module specified in RootModule/ModuleToProcess.<br /><br /> Adding a module name to this element is similar to calling `Import-Module` from within your script or assembly code. The main difference is that it's easier to see what you are loading here in the manifest file. Also, if a module fails to load here, you will not yet have loaded your actual module.<br /><br /> In addition to other modules, you may also load script (.ps1) files here. These files will execute in the context of the root module. (This is equivalent to dot sourcing the script in your root module.)|
83+
|FunctionsToExport<br /><br /> Type: [string[]]|@()|Specifies the functions that the module exports (wildcard characters are permitted but discouraged) to the caller's session state. By default, no functions are exported. You can use this key to list the functions that are exported by the module.<br /><br /> The caller's session state can be the global session state or, for nested modules, the session state of another module. When chaining nested modules, all functions that are exported by a nested module will be exported to the global session state unless a module in the chain restricts the function by using the FunctionsToExport key.<br /><br /> If the manifest also exports aliases for the functions, this key can remove functions whose aliases are listed in the AliasesToExport key, but this key cannot add function aliases to the list.|
84+
|CmdletsToExport<br /><br /> Type: [string[]]|@()|Specifies the cmdlets that the module exports (wildcard characters are permitted but discouraged). By default, no cmdlets are exported. You can use this key to list the cmdlets that are exported by the module.<br /><br /> The caller's session state can be the global session state or, for nested modules, the session state of another module. When you are chaining nested modules, all cmdlets that are exported by a nested module will be ultimately exported to the global session state unless a module in the chain restricts the cmdlet by using the CmdletsToExport key.<br /><br /> If the manifest also exports aliases for the cmdlets, this key can remove cmdlets whose aliases are listed in the AliasesToExport key, but this key cannot add cmdlet aliases to the list.|
85+
|VariablesToExport<br /><br /> Type: string|'*'|Specifies the variables that the module exports (wildcard characters are permitted) to the caller's session state. By default, all variables are exported. You can use this key to restrict the variables that are exported by the module.<br /><br /> The caller's session state can be the global session state or, for nested modules, the session state of another module. When you are chaining nested modules, all variables that are exported by a nested module will be exported to the global session state unless a module in the chain restricts the variable by using the VariablesToExport key.<br /><br /> If the manifest also exports aliases for the variables, this key can remove variables whose aliases are listed in the AliasesToExport key, but this key cannot add variable aliases to the list.|
86+
|AliasesToExport<br /><br /> Type: [string[]]|@()|Specifies the aliases that the module exports (wildcard characters are permitted but discouraged) to the caller's session state. By default, no aliases are exported. You can use this key to list the aliases that are exported by the module.<br /><br /> The caller's session state can be the global session state or, for nested modules, the session state of another module. When you are chaining nested modules, all aliases that are exported by a nested module will be ultimately exported to the global session state unless a module in the chain restricts the alias by using the AliasesToExport key.|
8787
|ModuleList<br /><br /> Type: [string[]]|@()|Specifies all the modules that are packaged with this module. These modules can be entered by name (a comma-separated string) or as a hash table with ModuleName and GUID keys. The hash table can also have an optional ModuleVersion key. The ModuleList key is designed to act as a module inventory. These modules are not automatically processed.|
8888
|FileList<br /><br /> Type: [string[]]|@()|List of all files packaged with this module. As with ModuleList, FileList is to assist you as an inventory list, and is not otherwise processed.|
89-
|PrivateData<br /><br /> Type: [object]|' '|Specifies any private data that needs to be passed to the root module specified by the RootModule/ModuleToProcess key.|
89+
|PrivateData<br /><br /> Type: [object]|@{...}|Specifies any private data that needs to be passed to the root module specified by the RootModule/ModuleToProcess key.|
9090
|HelpInfoURI<br /><br /> Type: string|' '|HelpInfo URI of this module.|
9191
|DefaultCommandPrefix<br /><br /> Type: string|' '|Default prefix for commands exported from this module. Override the default prefix using `Import-Module` -Prefix.|
9292

@@ -100,19 +100,22 @@ The following sample module manifest shows the keys and default values in a modu
100100
#
101101
# Generated by: User01
102102
#
103-
# Generated on: 1/24/2012
103+
# Generated on: 2019-10-09
104104
#
105105
106106
@{
107107
108-
# Script module or binary module file associated with this manifest
109-
#RootModule = ''
108+
# Script module or binary module file associated with this manifest.
109+
# RootModule = ''
110110
111111
# Version number of this module.
112112
ModuleVersion = '1.0'
113113
114+
# Supported PSEditions
115+
# CompatiblePSEditions = @()
116+
114117
# ID used to uniquely identify this module
115-
GUID = 'd0a9150d-b6a4-4b17-a325-e3a24fed0aa9'
118+
GUID = 'b888e5a2-8578-4c0b-938d-0cd9b5b836ba'
116119
117120
# Author of this module
118121
Author = 'User01'
@@ -121,7 +124,7 @@ Author = 'User01'
121124
CompanyName = 'Unknown'
122125
123126
# Copyright statement for this module
124-
Copyright = '(c) 2012 User01. All rights reserved.'
127+
Copyright = '(c) 2019 User01. All rights reserved.'
125128
126129
# Description of the functionality provided by this module
127130
# Description = ''
@@ -135,10 +138,10 @@ Copyright = '(c) 2012 User01. All rights reserved.'
135138
# Minimum version of the Windows PowerShell host required by this module
136139
# PowerShellHostVersion = ''
137140
138-
# Minimum version of the .NET Framework required by this module
141+
# Minimum version of Microsoft .NET Framework required by this module. This prerequisite is valid for the PowerShell Desktop edition only.
139142
# DotNetFrameworkVersion = ''
140143
141-
# Minimum version of the common language runtime (CLR) required by this module
144+
# Minimum version of the common language runtime (CLR) required by this module. This prerequisite is valid for the PowerShell Desktop edition only.
142145
# CLRVersion = ''
143146
144147
# Processor architecture (None, X86, Amd64) required by this module
@@ -150,7 +153,7 @@ Copyright = '(c) 2012 User01. All rights reserved.'
150153
# Assemblies that must be loaded prior to importing this module
151154
# RequiredAssemblies = @()
152155
153-
# Script files (.ps1) that are run in the caller's environment prior to importing this module
156+
# Script files (.ps1) that are run in the caller's environment prior to importing this module.
154157
# ScriptsToProcess = @()
155158
156159
# Type files (.ps1xml) to be loaded when importing this module
@@ -162,26 +165,50 @@ Copyright = '(c) 2012 User01. All rights reserved.'
162165
# Modules to import as nested modules of the module specified in RootModule/ModuleToProcess
163166
# NestedModules = @()
164167
165-
# Functions to export from this module
166-
FunctionsToExport = '*'
168+
# Functions to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no functions to export.
169+
FunctionsToExport = @()
167170
168-
# Cmdlets to export from this module
169-
CmdletsToExport = '*'
171+
# Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export.
172+
CmdletsToExport = @()
170173
171174
# Variables to export from this module
172175
VariablesToExport = '*'
173176
174-
# Aliases to export from this module
175-
AliasesToExport = '*'
177+
# Aliases to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no aliases to export.
178+
AliasesToExport = @()
179+
180+
# DSC resources to export from this module
181+
# DscResourcesToExport = @()
176182
177183
# List of all modules packaged with this module
178184
# ModuleList = @()
179185
180186
# List of all files packaged with this module
181187
# FileList = @()
182188
183-
# Private data to pass to the module specified in RootModule/ModuleToProcess
184-
# PrivateData = ''
189+
# Private data to pass to the module specified in RootModule/ModuleToProcess. This may also contain a PSData hashtable with additional module metadata used by PowerShell.
190+
PrivateData = @{
191+
192+
PSData = @{
193+
194+
# Tags applied to this module. These help with module discovery in online galleries.
195+
# Tags = @()
196+
197+
# A URL to the license for this module.
198+
# LicenseUri = ''
199+
200+
# A URL to the main website for this project.
201+
# ProjectUri = ''
202+
203+
# A URL to an icon representing this module.
204+
# IconUri = ''
205+
206+
# ReleaseNotes of this module
207+
# ReleaseNotes = ''
208+
209+
} # End of PSData hashtable
210+
211+
} # End of PrivateData hashtable
185212
186213
# HelpInfo URI of this module
187214
# HelpInfoURI = ''

0 commit comments

Comments
 (0)