如何撰寫 PowerShell 模組資訊清單How to write a PowerShell module manifest

撰寫 PowerShell 模組之後,您可以新增包含模組相關資訊的選擇性模組資訊清單。After you've written your PowerShell module, you can add an optional module manifest that includes information about the module. 例如,您可以描述作者、指定模組中的檔案(例如,嵌套模組)、執行腳本以自訂使用者的環境、載入類型和格式檔案、定義系統需求,以及限制模組匯出的成員。For example, you can describe the author, specify files in the module (such as nested modules), run scripts to customize the user's environment, load type and formatting files, define system requirements, and limit the members that the module exports.

建立模組資訊清單Creating a module manifest

模組資訊清單是 PowerShell 資料檔案( .psd1 ),可描述模組的內容,並決定模組的處理方式。A module manifest is a PowerShell data file (.psd1) that describes the contents of a module and determines how a module is processed. 資訊清單檔案是文字檔,其中包含索引鍵和值的雜湊表。The manifest file is a text file that contains a hash table of keys and values. 您可以將資訊清單檔連結至模組,方法是將資訊清單命名為與模組相同,並將資訊清單儲存在模組的根目錄中。You link a manifest file to a module by naming the manifest the same as the module, and storing the manifest in the module's root directory.

針對只包含單一 .psm1 或二進位元件的簡單模組,模組資訊清單是選擇性的。For simple modules that contain only a single .psm1 or binary assembly, a module manifest is optional. 但建議您盡可能使用模組資訊清單,因為它們有助於您組織程式碼及維護版本設定資訊。But, the recommendation is to use a module manifest whenever possible, as they're useful to help you organize your code and maintain versioning information. 此外,需要模組資訊清單才能匯出安裝在全域組件快取中的元件。And, a module manifest is required to export an assembly that is installed in the Global Assembly Cache. 支援可更新的說明功能的模組也需要模組資訊清單。A module manifest is also required for modules that support the Updatable Help feature. 「可更新的說明」使用模組資訊清單中的HelpInfoUri索引鍵來尋找說明資訊(HelpInfo XML)檔案,其中包含模組的已更新說明檔的位置。Updatable Help uses the HelpInfoUri key in the module manifest to find the Help information (HelpInfo XML) file that contains the location of the updated help files for the module. 如需「可更新的說明」的詳細資訊,請參閱支援可更新的協助For more information about Updatable Help, see Supporting Updatable Help.

若要建立和使用模組資訊清單To create and use a module manifest

  1. 建立模組資訊清單的最佳做法是使用new-modulemanifest Cmdlet。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. New-ModuleManifest使用您指定的值建立模組資訊清單,並包含其餘的索引鍵及其預設值。New-ModuleManifest creates a module manifest with your specified values, and includes the remaining keys and their default values. 如果您需要建立多個模組,請使用 New-ModuleManifest 來建立可針對不同模組修改的模組資訊清單範本。If you need to create multiple modules, use New-ModuleManifest to create a module manifest template that can be modified for your different modules. 如需預設模組資訊清單的範例,請參閱範例模組資訊清單For an example of a default module manifest, see the Sample module manifest.

    New-ModuleManifest -Path C:\myModuleName.psd1 -ModuleVersion "2.0" -Author "YourNameHere"

    另一個替代方式是使用所需的最少資訊( ModuleVersion)手動建立模組資訊清單的雜湊表。An alternative is to manually create the module manifest's hash table using the minimal information required, the ModuleVersion. 您可以使用與模組相同的名稱來儲存檔案,並使用 .psd1 副檔名。You save the file with the same name as your module and use the .psd1 file extension. 接著,您可以編輯檔案,並新增適當的索引鍵和值。You can then edit the file and add the appropriate keys and values.

  2. 在資訊清單檔中新增您想要的任何其他元素。Add any additional elements that you want in the manifest file.

    若要編輯資訊清單檔,請使用您偏好的任何文字編輯器。To edit the manifest file, use any text editor you prefer. 不過,資訊清單檔案是包含程式碼的腳本檔案,因此您可能會想要在腳本或開發環境(例如 Visual Studio Code)中編輯它。But, the manifest file is a script file that contains code, so you may wish to edit it in a scripting or development environment, such as Visual Studio Code. 資訊清單檔案的所有元素都是選擇性的,但ModuleVersion號碼除外。All elements of a manifest file are optional, except for the ModuleVersion number.

    如需可在模組資訊清單中包含的索引鍵和值的說明,請參閱模組資訊清單元素表。For descriptions of the keys and values you can include in a module manifest, see the Module manifest elements table. 如需詳細資訊,請參閱new-modulemanifest Cmdlet 中的參數說明。For more information, see the parameter descriptions in the New-ModuleManifest cmdlet.

  3. 若要解決基底模組資訊清單元素可能不會涵蓋的任何案例,您可以選擇將其他程式碼加入模組資訊清單。To address any scenarios that might not be covered by the base module manifest elements, you have the option to add additional code to your module manifest.

    基於安全性考慮,PowerShell 只會在模組資訊清單檔案中執行一小部分的可用作業。For security concerns, PowerShell only runs a small subset of the available operations in a module manifest file. 一般來說,您可以使用 if 語句、算術和比較運算子,以及基本的 PowerShell 資料類型。Generally, you can use the if statement, arithmetic and comparison operators, and the basic PowerShell data types.

  4. 建立模組資訊清單之後,您可以測試它,以確認資訊清單中所描述的任何路徑是否正確。After you've created your module manifest, you can test it to confirm that any paths described in the manifest are correct. 若要測試您的模組資訊清單,請使用測試 new-modulemanifestTo test your module manifest, use Test-ModuleManifest.

    Test-ModuleManifest myModuleName.psd1

  5. 請確定您的模組資訊清單位於包含模組的目錄最上層。Be sure that your module manifest is located in the top level of the directory that contains your module.

    當您將模組複製到系統上並將它匯入時,PowerShell 會使用模組資訊清單來匯入您的模組。When you copy your module onto a system and import it, PowerShell uses the module manifest to import your module.

  6. (選擇性)您可以在資訊清單本身的情況下,直接透過點對匯入模組的呼叫來測試模組資訊清單。Optionally, you can directly test your module manifest with a call to Import-Module by dot-sourcing the manifest itself.

    Import-Module .\myModuleName.psd1

模組資訊清單元素Module manifest elements

下表描述可在模組資訊清單中包含的元素。The following table describes the elements you can include in a module manifest.

元素Element 預設Default 描述Description
RootModuleRootModule
輸入: StringType: String
<empty string> 與這個資訊清單相關聯的腳本模組或二進位模組檔案。Script module or binary module file associated with this manifest. 先前的 PowerShell 版本稱為此元素ModuleToProcessPrevious versions of PowerShell called this element the ModuleToProcess.
根模組的可能類型可以是空的,它會建立資訊清單模組、腳本模組的名稱( .psm1 ),或二進位模組的名稱( .exe.dll )。Possible types for the root module can be empty, which creates a Manifest module, the name of a script module (.psm1), or the name of a binary module (.exe or .dll). 將模組資訊清單的名稱( .psd1 )或腳本檔案()放 .ps1 在此元素中會造成錯誤。Placing the name of a module manifest (.psd1) or a script file (.ps1) in this element causes an error.
範例: RootModule = 'ScriptModule.psm1'Example: RootModule = 'ScriptModule.psm1'
ModuleVersionModuleVersion
輸入: VersionType: Version
'0.0.1' 此模組的版本號碼。Version number of this module. 如果未指定值,則會 New-ModuleManifest 使用預設值。If a value isn't specified, New-ModuleManifest uses the default. 此字串必須能夠轉換成類型,例如 Version #.#.#.#.#The string must be able to convert to the type Version for example #.#.#.#.#. Import-Module載入它在符合名稱的 $PSModulePath上找到的第一個模組,而且至少有ModuleVersion,做為MinimumVersion參數。Import-Module loads the first module it finds on the $PSModulePath that matches the name, and has at least as high a ModuleVersion, as the MinimumVersion parameter. 若要匯入特定版本,請使用 Import-Module Cmdlet 的RequiredVersion參數。To import a specific version, use the Import-Module cmdlet's RequiredVersion parameter.
範例: ModuleVersion = '1.0'Example: ModuleVersion = '1.0'
GUIDGUID
輸入: GUIDType: GUID
'<GUID>' 用來唯一識別此模組的識別碼。ID used to uniquely identify this module. 如果未指定值,請 New-ModuleManifest 會自動產生值。If a value isn't specified, New-ModuleManifest autogenerates the value. 您目前無法依GUID匯入模組。You can't currently import a module by GUID.
範例: GUID = 'cfc45206-1e49-459d-a8ad-5b571ef94857'Example: GUID = 'cfc45206-1e49-459d-a8ad-5b571ef94857'
作者Author
輸入: StringType: String
'<Current user>' 此課程模組的作者。Author of this module. 如果未指定值,會 New-ModuleManifest 使用目前的使用者。If a value isn't specified, New-ModuleManifest uses the current user.
範例: Author = 'AuthorNameHere'Example: Author = 'AuthorNameHere'
CompanyNameCompanyName
輸入: StringType: String
'Unknown' 本課程模組的公司或廠商。Company or vendor of this module. 如果未指定值,則會 New-ModuleManifest 使用預設值。If a value isn't specified, New-ModuleManifest uses the default.
範例: CompanyName = 'Fabrikam'Example: CompanyName = 'Fabrikam'
詳情Copyright
輸入: StringType: String
'(c) <Author>. All rights reserved.' 本課程模組的著作權聲明。Copyright statement for this module. 如果未指定值,會 New-ModuleManifest 使用目前使用者的預設值做為 <Author>If a value isn't specified, New-ModuleManifest uses the default with the current user as the <Author>. 若要指定作者,請使用author參數。To specify an author, use the Author parameter.
範例: Copyright = '2019 AuthorName. All rights reserved.'Example: Copyright = '2019 AuthorName. All rights reserved.'
描述Description
輸入: StringType: String
<empty string> 此模組所提供的功能描述。Description of the functionality provided by this module.
範例: Description = 'This is the module's description.'Example: Description = 'This is the module's description.'
PowerShellVersionPowerShellVersion
輸入: VersionType: Version
<empty string> 此模組所需的最小 PowerShell 引擎版本。Minimum version of the PowerShell engine required by this module. 有效的值為1.0、2.0、3.0、4.0、5.0、5.1、6和7。Valid values are 1.0, 2.0, 3.0, 4.0, 5.0, 5.1, 6, and 7.
範例: PowerShellVersion = '5.0'Example: PowerShellVersion = '5.0'
PowerShellHostNamePowerShellHostName
輸入: StringType: String
<empty string> 此模組所需的 PowerShell 主機名稱。Name of the PowerShell host required by this module. 這個名稱是由 PowerShell 提供。This name is provided by PowerShell. 若要尋找主機程式的名稱,請在程式中輸入: $host.nameTo find the name of a host program, in the program, type: $host.name.
範例: PowerShellHostName = 'ConsoleHost'Example: PowerShellHostName = 'ConsoleHost'
PowerShellHostVersionPowerShellHostVersion
輸入: VersionType: Version
<empty string> 此模組所需的 PowerShell 主機最低版本。Minimum version of the PowerShell host required by this module.
範例: PowerShellHostVersion = '2.0'Example: PowerShellHostVersion = '2.0'
DotNetFrameworkVersionDotNetFrameworkVersion
輸入: VersionType: Version
<empty string> 本課程模組所需的 Microsoft .NET Framework 最低版本。Minimum version of Microsoft .NET Framework required by this module. 這項必要條件僅適用于 PowerShell Desktop 版本,例如 PowerShell 5.1。This prerequisite is valid for the PowerShell Desktop edition only, such as PowerShell 5.1.
範例: DotNetFrameworkVersion = '3.5'Example: DotNetFrameworkVersion = '3.5'
CLRVersionCLRVersion
輸入: VersionType: Version
<empty string> 此模組所需的最小 common language runtime (CLR)版本。Minimum version of the common language runtime (CLR) required by this module. 這項必要條件僅適用于 PowerShell Desktop 版本,例如 PowerShell 5.1。This prerequisite is valid for the PowerShell Desktop edition only, such as PowerShell 5.1.
範例: CLRVersion = '3.5'Example: CLRVersion = '3.5'
ProcessorArchitectureProcessorArchitecture
輸入: ProcessorArchitectureType: ProcessorArchitecture
<empty string> 此模組所需的處理器架構(None、X86、Amd64)。Processor architecture (None, X86, Amd64) required by this module. 有效值為 x86、AMD64、Arm、IA64、MSIL 和 None (未知或未指定)。Valid values are x86, AMD64, Arm, IA64, MSIL, and None (unknown or unspecified).
範例: ProcessorArchitecture = 'x86'Example: ProcessorArchitecture = 'x86'
RequiredModulesRequiredModules
輸入: Object[]Type: Object[]
@() 在匯入此模組之前,必須先匯入至全域環境的模組。Modules that must be imported into the global environment prior to importing this module. 這會載入任何列出的模組,除非它們已經載入。This loads any modules listed unless they've already been loaded. 例如,有些模組可能已經由其他模組載入。For example, some modules may already be loaded by a different module. 您可以使用來指定要載入的特定版本, RequiredVersion 而不是 ModuleVersionIt's possible to specify a specific version to load using RequiredVersion rather than ModuleVersion. ModuleVersion 使用時,它會載入最少指定版本的可用最新版本。When ModuleVersion is used it will load the newest version available with a minimum of the version specified. 您可以在參數值中結合字串和雜湊表。You can combine strings and hash tables in the parameter value.
範例: RequiredModules = @("MyModule", @{ModuleName="MyDependentModule"; ModuleVersion="2.0"; GUID="cfc45206-1e49-459d-a8ad-5b571ef94857"})Example: RequiredModules = @("MyModule", @{ModuleName="MyDependentModule"; ModuleVersion="2.0"; GUID="cfc45206-1e49-459d-a8ad-5b571ef94857"})
範例: RequiredModules = @("MyModule", @{ModuleName="MyDependentModule"; RequiredVersion="1.5"; GUID="cfc45206-1e49-459d-a8ad-5b571ef94857"})Example: RequiredModules = @("MyModule", @{ModuleName="MyDependentModule"; RequiredVersion="1.5"; GUID="cfc45206-1e49-459d-a8ad-5b571ef94857"})
RequiredAssembliesRequiredAssemblies
輸入: String[]Type: String[]
@() 必須在匯入此模組之前載入的元件。Assemblies that must be loaded prior to importing this module. 指定模組所需的元件( .dll )檔案名。Specifies the assembly (.dll) file names that the module requires.
PowerShell 會先載入指定的元件,再更新類型或格式、匯入嵌套模組,或匯入 RootModule 索引鍵值中所指定的模組檔案。PowerShell loads the specified assemblies before updating types or formats, importing nested modules, or importing the module file that is specified in the value of the RootModule key. 使用此參數來列出模組所需的所有元件。Use this parameter to list all the assemblies that the module requires.
範例: RequiredAssemblies = @("assembly1.dll", "assembly2.dll", "assembly3.dll")Example: RequiredAssemblies = @("assembly1.dll", "assembly2.dll", "assembly3.dll")
Scriptstoprocess 索引ScriptsToProcess
輸入: String[]Type: String[]
@() .ps1 入模組時,在呼叫者會話狀態中執行的腳本()檔案。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 log in script.
這些腳本會在載入資訊清單中列出的任何模組之前執行。These scripts are run before any of the modules listed in the manifest are loaded.
範例: ScriptsToProcess = @("script1.ps1", "script2.ps1", "script3.ps1")Example: ScriptsToProcess = @("script1.ps1", "script2.ps1", "script3.ps1")
TypesToProcessTypesToProcess
輸入: String[]Type: String[]
@() .ps1xml 入此模組時要載入的類型檔案()。Type files (.ps1xml) to be loaded when importing this module.
範例: TypesToProcess = @("type1.ps1xml", "type2.ps1xml", "type3.ps1xml")Example: TypesToProcess = @("type1.ps1xml", "type2.ps1xml", "type3.ps1xml")
FormatsToProcessFormatsToProcess
輸入: String[]Type: String[]
@() .ps1xml 入此模組時要載入的格式檔案()。Format files (.ps1xml) to be loaded when importing this module.
範例: FormatsToProcess = @("format1.ps1xml", "format2.ps1xml", "format3.ps1xml")Example: FormatsToProcess = @("format1.ps1xml", "format2.ps1xml", "format3.ps1xml")
NestedModulesNestedModules
輸入: Object[]Type: Object[]
@() 要匯入為RootModule (別名:ModuleToProcess)中所指定模組之嵌套模組的模組。Modules to import as nested modules of the module specified in RootModule (alias:ModuleToProcess).
將模組名稱加入這個專案,類似于 Import-Module 從您的腳本或元件程式碼中呼叫。Adding a module name to this element is similar to calling Import-Module from within your script or assembly code. 使用資訊清單檔案的主要差異在於,您可以更輕鬆地查看所要載入的內容。The main difference by using a manifest file is that it's easier to see what you're loading. 而且,如果模組無法載入,您還不會載入實際的模組。And, if a module fails to load, you will not yet have loaded your actual module.
除了其他模組之外,您也可以在這裡載入腳本( .ps1 )檔案。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.
範例: NestedModules = @("script.ps1", @{ModuleName="MyModule"; ModuleVersion="1.0.0.0"; GUID="50cdb55f-5ab7-489f-9e94-4ec21ff51e59"})Example: NestedModules = @("script.ps1", @{ModuleName="MyModule"; ModuleVersion="1.0.0.0"; GUID="50cdb55f-5ab7-489f-9e94-4ec21ff51e59"})
FunctionsToExportFunctionsToExport
輸入: String[]Type: String[]
@() 指定要從這個模組匯出的函式,若要獲得最佳效能,請不要使用萬用字元,也不要刪除專案,如果沒有可匯出的函式,請使用空陣列。Specifies the 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. 根據預設,不會匯出任何函式。By default, no functions are exported. 您可以使用此索引鍵來列出模組匯出的函式。You can use this key to list the functions that are exported by the module.
模組會將函式匯出至呼叫者的會話狀態。The module exports the functions to the caller's session state. 呼叫者的會話狀態可以是全域會話狀態,或是針對嵌套模組,另一個模組的會話狀態。The caller's session state can be the global session state or, for nested modules, the session state of another module. 連結嵌套模組時,除非鏈中的模組使用FunctionsToExport索引鍵來限制函式,否則,所有由嵌套模組匯出的函式都會匯出到全域會話狀態。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.
如果資訊清單匯出函式的別名,此索引鍵可以移除其別名列在AliasesToExport索引鍵中的函式,但此索引鍵無法將函式別名加入清單中。If the manifest 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.
範例: FunctionsToExport = @("function1", "function2", "function3")Example: FunctionsToExport = @("function1", "function2", "function3")
CmdletsToExportCmdletsToExport
輸入: String[]Type: String[]
@() 指定要從這個模組匯出的 Cmdlet,為了達到最佳效能,請不要使用萬用字元,也不要刪除專案,如果沒有可匯出的 Cmdlet,請使用空陣列。Specifies the 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. 根據預設,不會匯出任何 Cmdlet。By default, no cmdlets are exported. 您可以使用此金鑰來列出模組匯出的 Cmdlet。You can use this key to list the cmdlets that are exported by the module.
呼叫者的會話狀態可以是全域會話狀態,或是針對嵌套模組,另一個模組的會話狀態。The caller's session state can be the global session state or, for nested modules, the session state of another module. 當您要連結嵌套模組時,所有由嵌套模組匯出的 Cmdlet 都會匯出到全域會話狀態,除非鏈中的模組使用CmdletsToExport金鑰來限制此 Cmdlet。When you're chaining nested modules, all cmdlets that are exported by a nested module will be exported to the global session state unless a module in the chain restricts the cmdlet by using the CmdletsToExport key.
如果資訊清單匯出 Cmdlet 的別名,此金鑰可以移除AliasesToExport機碼中列出其別名的 Cmdlet,但此金鑰無法將 Cmdlet 別名新增至清單。If the manifest 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.
範例: CmdletsToExport = @("Get-MyCmdlet", "Set-MyCmdlet", "Test-MyCmdlet")Example: CmdletsToExport = @("Get-MyCmdlet", "Set-MyCmdlet", "Test-MyCmdlet")
VariablesToExportVariablesToExport
輸入: String[]Type: String[]
'*' 指定模組匯出至呼叫者會話狀態的變數。Specifies the variables that the module exports to the caller's session state. 允許使用萬用字元。Wildcard characters are permitted. 預設會匯出所有變數( '*' )。By default, all variables ('*') are exported. 您可以使用此金鑰來限制模組匯出的變數。You can use this key to restrict the variables that are exported by the module.
呼叫者的會話狀態可以是全域會話狀態,或是針對嵌套模組,另一個模組的會話狀態。The caller's session state can be the global session state or, for nested modules, the session state of another module. 當您要連結嵌套模組時,所有由嵌套模組匯出的變數都會匯出到全域會話狀態,除非鏈中的模組使用VariablesToExport索引鍵來限制變數。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.
如果資訊清單也會匯出變數的別名,此索引鍵可以移除別名列在AliasesToExport索引鍵中的變數,但此索引鍵無法將變數別名加入清單中。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.
範例: VariablesToExport = @('$MyVariable1', '$MyVariable2', '$MyVariable3')Example: VariablesToExport = @('$MyVariable1', '$MyVariable2', '$MyVariable3')
AliasesToExportAliasesToExport
輸入: String[]Type: String[]
@() 指定要從這個模組匯出的別名,為了達到最佳效能,請不要使用萬用字元,也不要刪除專案,如果沒有可匯出的別名,請使用空陣列。Specifies the 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. 根據預設,不會匯出任何別名。By default, no aliases are exported. 您可以使用此金鑰來列出模組匯出的別名。You can use this key to list the aliases that are exported by the module.
此模組會將別名匯出至呼叫者的會話狀態。The module exports the aliases to caller's session state. 呼叫者的會話狀態可以是全域會話狀態,或是針對嵌套模組,另一個模組的會話狀態。The caller's session state can be the global session state or, for nested modules, the session state of another module. 當您要連結嵌套模組時,所有由嵌套模組匯出的別名最終都會匯出到全域會話狀態,除非鏈中的模組使用AliasesToExport索引鍵來限制別名。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.
範例: AliasesToExport = @("MyAlias1", "MyAlias2", "MyAlias3")Example: AliasesToExport = @("MyAlias1", "MyAlias2", "MyAlias3")
DscResourcesToExportDscResourcesToExport
輸入: String[]Type: String[]
@() 指定要從這個模組匯出的 DSC 資源。Specifies DSC resources to export from this module. 允許使用萬用字元。Wildcards are permitted.
範例: DscResourcesToExport = @("DscResource1", "DscResource2", "DscResource3")Example: DscResourcesToExport = @("DscResource1", "DscResource2", "DscResource3")
ModuleListModuleList
輸入: Object[]Type: Object[]
@() 指定與此模組一起封裝的所有模組。Specifies all the modules that are packaged with this module. 這些模組可以依名稱輸入、使用逗點分隔字串,或當做具有ModuleNameGUID金鑰的雜湊表。These modules can be entered by name, using a comma-separated string, or as a hash table with ModuleName and GUID keys. 雜湊表也可以有選擇性的ModuleVersion索引鍵。The hash table can also have an optional ModuleVersion key. ModuleList索引鍵是設計來作為模組清查。The ModuleList key is designed to act as a module inventory. 這些模組不會自動處理。These modules are not automatically processed.
範例: ModuleList = @("SampleModule", "MyModule", @{ModuleName="MyModule"; ModuleVersion="1.0.0.0"; GUID="50cdb55f-5ab7-489f-9e94-4ec21ff51e59"})Example: ModuleList = @("SampleModule", "MyModule", @{ModuleName="MyModule"; ModuleVersion="1.0.0.0"; GUID="50cdb55f-5ab7-489f-9e94-4ec21ff51e59"})
檔案清單FileList
輸入: String[]Type: String[]
@() 此課程模組所封裝之所有檔案的清單。List of all files packaged with this module. 如同ModuleListFileList是一份清查清單,不會進行其他處理。As with ModuleList, FileList is an inventory list, and isn't otherwise processed.
範例: FileList = @("File1", "File2", "File3")Example: FileList = @("File1", "File2", "File3")
PrivateDataPrivateData
輸入: ObjectType: Object
@{...} 指定需要傳遞至RootModule (Alias: ModuleToProcess)索引鍵所指定之根模組的任何私用資料。Specifies any private data that needs to be passed to the root module specified by the RootModule (alias: ModuleToProcess) key. PrivateData是包含數個元素的雜湊表 : TagsLicenseUriProjectURIIconUriReleaseNotes發行前版本、 RequireLicenseAcceptanceExternalModuleDependenciesPrivateData is a hash table that comprises several elements: Tags, LicenseUri, ProjectURI, IconUri, ReleaseNotes, Prerelease, RequireLicenseAcceptance, and ExternalModuleDependencies.
標籤Tags
輸入: String[]Type: String[]
@() 標籤有助於線上資源庫中的模組探索。Tags help with module discovery in online galleries.
範例: Tags = "PackageManagement", "PowerShell", "Manifest"Example: Tags = "PackageManagement", "PowerShell", "Manifest"
LicenseUriLicenseUri
輸入: UriType: Uri
<empty string> 此模組的授權 URL。A URL to the license for this module.
範例: LicenseUri = 'https://www.contoso.com/license'Example: LicenseUri = 'https://www.contoso.com/license'
ProjectUriProjectUri
輸入: UriType: Uri
<empty string> 這個專案之主要網站的 URL。A URL to the main website for this project.
範例: ProjectUri = 'https://www.contoso.com/project'Example: ProjectUri = 'https://www.contoso.com/project'
IconUriIconUri
輸入: UriType: Uri
<empty string> 代表此模組的圖示 URL。A URL to an icon representing this module.
範例: IconUri = 'https://www.contoso.com/icons/icon.png'Example: IconUri = 'https://www.contoso.com/icons/icon.png'
ReleaseNotesReleaseNotes
輸入: StringType: String
<empty string> 指定模組的版本資訊。Specifies the module's release notes.
範例: ReleaseNotes = 'The release notes provide information about the module.Example: ReleaseNotes = 'The release notes provide information about the module.
PreRelease
輸入: StringType: String
<empty string> 這個參數已在 PowerShellGet 1.6.6 中新增。This parameter was added in PowerShellGet 1.6.6. 預先發行的字串,可將模組識別為線上元件庫中的發行前版本。A PreRelease string that identifies the module as a prerelease version in online galleries.
範例: PreRelease = 'This module is a prerelease version.Example: PreRelease = 'This module is a prerelease version.
RequireLicenseAcceptanceRequireLicenseAcceptance
輸入: BooleanType: Boolean
$true 這個參數已在 PowerShellGet 1.5 中新增。This parameter was added in PowerShellGet 1.5. 旗標,指出模組是否需要明確的使用者接受以進行安裝、更新或儲存。Flag to indicate whether the module requires explicit user acceptance for install, update, or save.
範例: RequireLicenseAcceptance = $falseExample: RequireLicenseAcceptance = $false
ExternalModuleDependenciesExternalModuleDependencies
輸入: String[]Type: String[]
@() 這個參數已在 PowerShellGet v2 中新增。This parameter was added in PowerShellGet v2. 此模組相依的外部模組清單。A list of external modules that this module is dependent upon.
範例: ExternalModuleDependencies = @("ExtModule1", "ExtModule2", "ExtModule3")Example: ExternalModuleDependencies = @("ExtModule1", "ExtModule2", "ExtModule3")
HelpInfoURIHelpInfoURI
輸入: StringType: String
<empty string> 此模組的 HelpInfo URI。HelpInfo URI of this module.
範例: HelpInfoURI = 'https://www.contoso.com/help'Example: HelpInfoURI = 'https://www.contoso.com/help'
DefaultCommandPrefixDefaultCommandPrefix
輸入: StringType: String
<empty string> 從這個模組匯出之命令的預設前置詞。Default prefix for commands exported from this module. 使用覆寫預設前置詞 Import-Module -PrefixOverride the default prefix using Import-Module -Prefix.
範例: DefaultCommandPrefix = 'My'Example: DefaultCommandPrefix = 'My'

範例模組資訊清單Sample module manifest

下列範例模組資訊清單是 New-ModuleManifest 在 PowerShell 7 中建立,並包含預設的索引鍵和值。The following sample module manifest was created with New-ModuleManifest in PowerShell 7 and contains the default keys and values.

#
# Module manifest for module 'SampleModuleManifest'
#
# Generated by: User01
#
# Generated on: 10/15/2019
#

@{

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

# Version number of this module.
ModuleVersion = '0.0.1'

# Supported PSEditions
# CompatiblePSEditions = @()

# ID used to uniquely identify this module
GUID = 'b632e90c-df3d-4340-9f6c-3b832646bf87'

# Author of this module
Author = 'User01'

# Company or vendor of this module
CompanyName = 'Unknown'

# Copyright statement for this module
Copyright = '(c) User01. All rights reserved.'

# Description of the functionality provided by this module
# Description = ''

# Minimum version of the PowerShell engine required by this module
# PowerShellVersion = ''

# Name of the PowerShell host required by this module
# PowerShellHostName = ''

# Minimum version of the PowerShell host required by this module
# PowerShellHostVersion = ''

# Minimum version of Microsoft .NET Framework required by this module. This prerequisite is valid for the PowerShell Desktop edition only.
# DotNetFrameworkVersion = ''

# Minimum version of the common language runtime (CLR) required by this module. This prerequisite is valid for the PowerShell Desktop edition only.
# CLRVersion = ''

# Processor architecture (None, X86, Amd64) required by this module
# ProcessorArchitecture = ''

# Modules that must be imported into the global environment prior to importing this module
# RequiredModules = @()

# Assemblies that must be loaded prior to importing this module
# RequiredAssemblies = @()

# Script files (.ps1) that are run in the caller's environment prior to importing this module.
# ScriptsToProcess = @()

# Type files (.ps1xml) to be loaded when importing this module
# TypesToProcess = @()

# Format files (.ps1xml) to be loaded when importing this module
# FormatsToProcess = @()

# Modules to import as nested modules of the module specified in RootModule/ModuleToProcess
# NestedModules = @()

# 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.
FunctionsToExport = @()

# 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.
CmdletsToExport = @()

# Variables to export from this module
VariablesToExport = '*'

# 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.
AliasesToExport = @()

# DSC resources to export from this module
# DscResourcesToExport = @()

# List of all modules packaged with this module
# ModuleList = @()

# List of all files packaged with this module
# FileList = @()

# 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.
PrivateData = @{

    PSData = @{

        # Tags applied to this module. These help with module discovery in online galleries.
        # Tags = @()

        # A URL to the license for this module.
        # LicenseUri = ''

        # A URL to the main website for this project.
        # ProjectUri = ''

        # A URL to an icon representing this module.
        # IconUri = ''

        # ReleaseNotes of this module
        # ReleaseNotes = ''

        # Prerelease string of this module
        # Prerelease = ''

        # Flag to indicate whether the module requires explicit user acceptance for install/update/save
        RequireLicenseAcceptance = $true

        # External dependent modules of this module
        # ExternalModuleDependencies = @()

    } # End of PSData hashtable

} # End of PrivateData hashtable

# HelpInfo URI of this module
# HelpInfoURI = ''

# Default prefix for commands exported from this module. Override the default prefix using Import-Module -Prefix.
# DefaultCommandPrefix = ''

}

另請參閱See also

about_Comparison_Operatorsabout_Comparison_Operators

about_Ifabout_If

全域組件快取Global Assembly Cache

Import-moduleImport-Module

New-ModuleManifestNew-ModuleManifest

Test-ModuleManifestTest-ModuleManifest

Update-ModuleManifestUpdate-ModuleManifest

撰寫 Windows PowerShell 模組Writing a Windows PowerShell Module