New-ModuleManifest
建立新的模組指令清單。
語法
New-ModuleManifest
[-Path] <String>
[-NestedModules <Object[]>]
[-Guid <Guid>]
[-Author <String>]
[-CompanyName <String>]
[-Copyright <String>]
[-RootModule <String>]
[-ModuleVersion <Version>]
[-Description <String>]
[-ProcessorArchitecture <ProcessorArchitecture>]
[-PowerShellVersion <Version>]
[-CLRVersion <Version>]
[-DotNetFrameworkVersion <Version>]
[-PowerShellHostName <String>]
[-PowerShellHostVersion <Version>]
[-RequiredModules <Object[]>]
[-TypesToProcess <String[]>]
[-FormatsToProcess <String[]>]
[-ScriptsToProcess <String[]>]
[-RequiredAssemblies <String[]>]
[-FileList <String[]>]
[-ModuleList <Object[]>]
[-FunctionsToExport <String[]>]
[-AliasesToExport <String[]>]
[-VariablesToExport <String[]>]
[-CmdletsToExport <String[]>]
[-DscResourcesToExport <String[]>]
[-CompatiblePSEditions <String[]>]
[-PrivateData <Object>]
[-Tags <String[]>]
[-ProjectUri <Uri>]
[-LicenseUri <Uri>]
[-IconUri <Uri>]
[-ReleaseNotes <String>]
[-Prerelease <String>]
[-RequireLicenseAcceptance]
[-ExternalModuleDependencies <String[]>]
[-HelpInfoUri <String>]
[-PassThru]
[-DefaultCommandPrefix <String>]
[-WhatIf]
[-Confirm]
[<CommonParameters>]
Description
New-ModuleManifest
Cmdlet 會建立新的模組指令清單 (.psd1
) 檔案、填入其值,並將指令清單檔案儲存在指定的路徑中。
模組作者可以使用此 Cmdlet 為其模組建立指令清單。 模組指令清單是包含哈希表的 .psd1
檔案。 哈希表中的索引鍵和值會描述模組的內容和屬性、定義必要條件,以及判斷元件的處理方式。 模組不需要指令清單。
New-ModuleManifest
會建立包含所有常用指令清單索引鍵的指令清單,因此您可以使用預設輸出做為指令清單範本。 若要新增或變更值,或新增此 Cmdlet 未新增的模組索引鍵,請在文本編輯器中開啟產生的檔案。
除了 Path 和 PassThru之外,每個參數都會建立模組指令清單索引鍵及其值。
在模組指令清單中,只需要 ModuleVersion 金鑰。 除非您在參數描述中指定,否則如果您省略命令中的參數,New-ModuleManifest
為沒有作用的相關聯值建立批注字串。
在 PowerShell 2.0 中,除了必要的參數值之外,New-ModuleManifest
會提示您輸入命令中未指定之常用參數的值。 從 PowerShell 3.0 開始,New-ModuleManifest
只有在未指定必要的參數值時才會提示。
如果您打算在 PowerShell 資源庫中發佈模組,指令清單必須包含特定屬性的值。 如需詳細資訊,請參閱資源庫檔中的 發佈至 PowerShell 資源庫之項目的必要元數據。
範例
範例 1 - 建立新的模組指令清單
此範例會在 Path 參數所指定的檔案中建立新的模組指令清單。 PassThru 參數會將輸出傳送至管線和檔案。
輸出會顯示指令清單中所有索引鍵的預設值。
New-ModuleManifest -Path C:\ps-test\Test-Module\Test-Module.psd1 -PassThru
#
# Module manifest for module 'Test-Module'
#
# Generated by: ContosoAdmin
#
# Generated on: 7/12/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 = 'e1826c6e-c420-4eef-9ac8-185e3669ca6a'
# Author of this module
Author = 'ContosoAdmin'
# Company or vendor of this module
CompanyName = 'Unknown'
# Copyright statement for this module
Copyright = '(c) ContosoAdmin. 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 = $false
# 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 = ''
}
範例 2 - 建立具有一些預先填入設定的新清單
此範例會建立新的模組指令清單。 它會使用 PowerShellVersion 和 AliasesToExport 參數,將值新增至對應的指令清單索引鍵。
$moduleSettings = @{
PowerShellVersion = 1.0
Path = 'C:\ps-test\ManifestTest.psd1'
AliasesToExport = @(
'JKBC'
'DRC'
'TAC'
)
}
New-ModuleManifest @moduleSettings
範例 3 - 建立需要其他模組的指令清單
這個範例會使用字串格式來指定 BitsTransfer 模組的名稱和哈希表格式來指定名稱、GUID,以及 PSScheduledJob 模組的版本。
$moduleSettings = @{
RequiredModules = ("BitsTransfer", @{
ModuleName="PSScheduledJob"
ModuleVersion="1.0.0.0";
GUID="50cdb55f-5ab7-489f-9e94-4ec21ff51e59"
})
Path = 'C:\ps-test\ManifestTest.psd1'
}
New-ModuleManifest @moduleSettings
這個範例示範如何使用 ModuleList、RequiredModules和 NestedModules 參數的字符串和哈希表格式。 您可以在相同的參數值中結合字串和哈希表。
範例 4 - 建立支援可更新說明的資訊清單
此範例會使用 HelpInfoUri 參數,在模組指令清單中建立 HelpInfoUri 機碼。 參數和索引鍵的值必須以 HTTP 開頭,或以 HTTPs 開頭。 這個值會告訴可更新的說明系統,在何處尋找模組的 HelpInfo XML 可更新說明資訊檔案。
$moduleSettings = @{
HelpInfoUri = 'http://https://go.microsoft.com/fwlink/?LinkID=603'
Path = 'C:\ps-test\ManifestTest.psd1'
}
New-ModuleManifest @moduleSettings
如需取得可更新說明的相關資訊,請參閱 about_Updatable_Help。 如需 HelpInfo XML 檔案的相關資訊,請參閱 支援可更新的說明。
範例 5 - 取得模組資訊
此範例示範如何取得模組的組態值。 模組指令清單中的值會反映在模組對象的屬性值中。
Get-Module
Cmdlet 用於使用 List 參數來取得 Microsoft.PowerShell.Diagnostics 模組。 命令會將模組傳送至 Format-List
Cmdlet,以顯示模組物件的所有屬性和值。
Get-Module Microsoft.PowerShell.Diagnostics -List | Format-List -Property *
LogPipelineExecutionDetails : False
Name : Microsoft.PowerShell.Diagnostics
Path : C:\Windows\system32\WindowsPowerShell\v1.0\Modules\Microsoft.PowerShell.Diagnostics\Micro
soft.PowerShell.Diagnostics.psd1
Definition :
Description :
Guid : ca046f10-ca64-4740-8ff9-2565dba61a4f
HelpInfoUri : https://go.microsoft.com/fwlink/?LinkID=210596
ModuleBase : C:\Windows\system32\WindowsPowerShell\v1.0\Modules\Microsoft.PowerShell.Diagnostics
PrivateData :
Version : 3.0.0.0
ModuleType : Manifest
Author : Microsoft Corporation
AccessMode : ReadWrite
ClrVersion : 4.0
CompanyName : Microsoft Corporation
Copyright : Microsoft Corporation. All rights reserved.
DotNetFrameworkVersion :
ExportedFunctions : {}
ExportedCmdlets : {[Get-WinEvent, Get-WinEvent], [Get-Counter, Get-Counter], [Import-Counter,
Import-Counter], [Export-Counter, Export-Counter]...}
ExportedCommands : {[Get-WinEvent, Get-WinEvent], [Get-Counter, Get-Counter], [Import-Counter,
Import-Counter], [Export-Counter, Export-Counter]...}
FileList : {}
ModuleList : {}
NestedModules : {}
PowerShellHostName :
PowerShellHostVersion :
PowerShellVersion : 3.0
ProcessorArchitecture : None
Scripts : {}
RequiredAssemblies : {}
RequiredModules : {}
RootModule :
ExportedVariables : {}
ExportedAliases : {}
ExportedWorkflows : {}
SessionState :
OnRemove :
ExportedFormatFiles : {C:\Windows\system32\WindowsPowerShell\v1.0\Event.format.ps1xml,
C:\Windows\system32\WindowsPowerShell\v1.0\Diagnostics.format.ps1xml}
ExportedTypeFiles : {C:\Windows\system32\WindowsPowerShell\v1.0\GetEvent.types.ps1xml}
參數
-AliasesToExport
指定模組導出的別名。 可以使用通配符。
您可以使用此參數來限制模組所導出的別名。 它可以從導出的別名清單中移除別名,但無法將別名新增至清單。
如果您省略此參數,New-ModuleManifest
會建立 AliasesToExport 索引鍵,其值為 *
(all),這表示模組中定義的所有別名都會由指令清單導出。
類型: | String[] |
Position: | Named |
預設值: | * (all) |
必要: | False |
接受管線輸入: | False |
接受萬用字元: | True |
-Author
指定模組作者。
如果您省略此參數,New-ModuleManifest
會以目前用戶的名稱建立 Author 機碼。
類型: | String |
Position: | Named |
預設值: | Name of the current user |
必要: | False |
接受管線輸入: | False |
接受萬用字元: | False |
-ClrVersion
指定模組所需Microsoft .NET Framework 的 Common Language Runtime (CLR) 最低版本。
注意
此設定僅適用於 PowerShell Desktop 版本,例如 Windows PowerShell 5.1,且僅適用於低於 4.5 的 .NET Framework 版本。 這項需求對較新版本的PowerShell或 .NET Framework 沒有任何作用。
類型: | Version |
Position: | Named |
預設值: | None |
必要: | False |
接受管線輸入: | False |
接受萬用字元: | False |
-CmdletsToExport
指定模組匯出的 cmdlet。 允許使用通配符。
您可以使用此參數來限制模組所導出的 Cmdlet。 它可以從導出的 Cmdlet 清單中移除 Cmdlet,但無法將 Cmdlet 新增至清單。
如果您省略此參數,New-ModuleManifest
會建立 CmdletsToExport 機碼,其值為 *
(all),這表示模組中定義的所有 Cmdlet 都會由指令清單導出。
類型: | String[] |
Position: | Named |
預設值: | * (all) |
必要: | False |
接受管線輸入: | False |
接受萬用字元: | True |
-CompanyName
識別建立模組的公司或廠商。
如果您省略此參數,New-ModuleManifest
會建立值為 “Unknown” 的 CompanyName 機碼。
類型: | String |
Position: | Named |
預設值: | "Unknown" |
必要: | False |
接受管線輸入: | False |
接受萬用字元: | False |
-CompatiblePSEditions
指定模組所相容的 PSEditions。 如需 PSEdition 的相關信息,請參閱 模組與相容的 PowerShell 版本。
類型: | String[] |
接受的值: | Desktop, Core |
Position: | Named |
預設值: | None |
必要: | False |
接受管線輸入: | False |
接受萬用字元: | False |
-Confirm
在執行 Cmdlet 之前,提示您進行確認。
類型: | SwitchParameter |
別名: | cf |
Position: | Named |
預設值: | False |
必要: | False |
接受管線輸入: | False |
接受萬用字元: | False |
-Copyright
指定模組的著作權聲明。
如果您省略此參數,New-ModuleManifest
會建立一個 版權 鍵,其中 (c) <year> <username>. All rights reserved.
是 <year>
(目前年份)的值,而 <username>
是 作者 鍵的值。
類型: | String |
Position: | Named |
預設值: | (c) <year> <username>. All rights reserved. |
必要: | False |
接受管線輸入: | False |
接受萬用字元: | False |
-DefaultCommandPrefix
指定當模組被匯入到會話中時,在模組中所有命令的名詞前加上的前置字。 輸入前置詞字串。 前置詞可防止用戶會話中的命令名稱衝突。
模組使用者可以藉由指定 Import-Module
Cmdlet 的 Prefix 參數來覆寫此前置詞。
此參數是在 PowerShell 3.0 中引進的。
類型: | String |
Position: | Named |
預設值: | None |
必要: | False |
接受管線輸入: | False |
接受萬用字元: | False |
-Description
描述模組的內容。
類型: | String |
Position: | Named |
預設值: | None |
必要: | False |
接受管線輸入: | False |
接受萬用字元: | False |
-DotNetFrameworkVersion
指定模組所需Microsoft .NET Framework 的最低版本。
注意
此設定僅適用於 PowerShell Desktop 版本,例如 Windows PowerShell 5.1,且僅適用於低於 4.5 的 .NET Framework 版本。 這項需求對較新版本的PowerShell或 .NET Framework 沒有任何作用。
類型: | Version |
Position: | Named |
預設值: | None |
必要: | False |
接受管線輸入: | False |
接受萬用字元: | False |
-DscResourcesToExport
指定模組匯出的 Desired State Configuration (DSC) 資源。 允許通配符。
類型: | String[] |
Position: | Named |
預設值: | None |
必要: | False |
接受管線輸入: | False |
接受萬用字元: | True |
-ExternalModuleDependencies
此模組相依的外部模組清單。
類型: | String[] |
Position: | Named |
預設值: | None |
必要: | False |
接受管線輸入: | False |
接受萬用字元: | False |
-FileList
指定模組中包含的所有項目。
此金鑰的設計目的是作為模組庫存。 發佈模組時,會包含密鑰中列出的檔案,但不會自動匯出任何函式。
類型: | String[] |
Position: | Named |
預設值: | None |
必要: | False |
接受管線輸入: | False |
接受萬用字元: | False |
-FormatsToProcess
指定匯入模組時執行的格式化檔案 (.ps1xml
)。
當您匯入模組時,PowerShell 會使用指定的檔案執行 Update-FormatData
Cmdlet。
由於格式化檔案的範圍並未設定,因此會影響會話中的所有會話狀態。
類型: | String[] |
Position: | Named |
預設值: | None |
必要: | False |
接受管線輸入: | False |
接受萬用字元: | False |
-FunctionsToExport
指定模組導出的函式。 允許通配符。
您可以使用此參數來限制模組所匯出的函式。 它可以從導出的別名清單中移除函式,但無法將函式新增至清單。
如果您省略此參數,New-ModuleManifest
會建立 FunctionsToExport 索引鍵,其值為 *
(all),這表示模組中定義的所有函式都會由指令清單導出。
類型: | String[] |
Position: | Named |
預設值: | * (all) |
必要: | False |
接受管線輸入: | False |
接受萬用字元: | True |
-Guid
指定模組的唯一識別碼。 GUID 可用來區分具有相同名稱的模組。
如果您省略此參數,New-ModuleManifest
會在清單中建立 GUID 索引鍵,並產生值的 GUID。
若要在 PowerShell 中建立新的 GUID,請輸入 [guid]::NewGuid()
。
類型: | Guid |
Position: | Named |
預設值: | A GUID generated for the module |
必要: | False |
接受管線輸入: | False |
接受萬用字元: | False |
-HelpInfoUri
指定模組 HelpInfo XML 檔案的因特網位址。 輸入以 HTTP 或 https開頭的統一資源識別碼 (URI)。
HelpInfo XML 檔案支援 PowerShell 3.0 中引進的可更新說明功能。 其中包含模組可下載說明檔的位置,以及每個支援地區設定的最新說明檔版本號碼的相關信息。
如需有關可更新說明的資訊,請參閱 about_Updatable_Help。 如需 HelpInfo XML 檔案的相關資訊,請參閱 支援可更新說明。
此參數是在 PowerShell 3.0 中引進的。
類型: | String |
Position: | Named |
預設值: | None |
必要: | False |
接受管線輸入: | False |
接受萬用字元: | False |
-IconUri
指定模組圖示的 URL。 指定的圖示會顯示在模組的資源庫網頁上。
類型: | Uri |
Position: | Named |
預設值: | None |
必要: | False |
接受管線輸入: | False |
接受萬用字元: | False |
-LicenseUri
指定模組的授權條款 URL。
類型: | Uri |
Position: | Named |
預設值: | None |
必要: | False |
接受管線輸入: | False |
接受萬用字元: | False |
-ModuleList
列出此課程模組中包含的所有模組。
輸入每個模組名稱做為字串,或輸入具有 ModuleName 和 ModuleVersion 索引鍵的哈希表。 哈希表也可以有可選的 GUID 鍵值。 您可以在參數值中結合字串和哈希表。
此金鑰的設計目的是要作為模組庫存。 不會自動處理此索引鍵值中列出的模組。
類型: | Object[] |
Position: | Named |
預設值: | None |
必要: | False |
接受管線輸入: | False |
接受萬用字元: | False |
-ModuleVersion
指定模組的版本。
不需要此參數,但指令清單中需要 ModuleVersion 密鑰。 如果您省略此參數,New-ModuleManifest
會建立值為 1.0 的 ModuleVersion 機碼。
類型: | Version |
Position: | Named |
預設值: | 1.0 |
必要: | False |
接受管線輸入: | False |
接受萬用字元: | False |
-NestedModules
指定匯入模組會話狀態的腳本模組(.psm1
)和二進位模組(.dll
)。
NestedModules 中的檔案 索引鍵會依照值中所列的順序執行。
輸入每個模組名稱做為字串,或輸入具有 ModuleName 和 ModuleVersion 索引鍵的哈希表。 哈希表也可以有選擇性 GUID 索引鍵。 您可以在參數值中結合字串和哈希表。
一般而言,巢狀模組包含根模組在其內部處理所需的命令。
根據預設,巢狀模組中的命令會從模組的會話狀態匯出至呼叫端的會話狀態,但根模組可以限制其導出的命令。 例如,使用 Export-ModuleMember
命令。
模組會話狀態中的巢狀模組可供根模組使用,但呼叫端會話狀態中的 Get-Module
命令不會傳回它們。
NestedModules 索引鍵中列出的腳本(.ps1
),是在模組的會話狀態中執行,而不是在呼叫端的會話狀態中執行。 若要在呼叫端的會話狀態中執行腳本,請在指令清單中 ScriptsToProcess 的值中列出腳本檔名 索引鍵。
類型: | Object[] |
Position: | Named |
預設值: | None |
必要: | False |
接受管線輸入: | False |
接受萬用字元: | False |
-PassThru
將產生的模組指令清單寫入主控台,並建立 .psd1
檔案。 根據預設,此 Cmdlet 不會產生任何輸出。
類型: | SwitchParameter |
Position: | Named |
預設值: | False |
必要: | False |
接受管線輸入: | False |
接受萬用字元: | False |
-Path
指定新模組指令清單的路徑和檔名。 輸入延伸名為 .psd1
的路徑和檔案名,例如 $pshome\Modules\MyModule\MyModule.psd1
。 需要 Path 參數。
如果您指定現有檔案的路徑,除非檔案具有只讀屬性,否則 New-ModuleManifest
取代檔案而不發出警告。
指令清單應該位於模組的目錄中,而指令清單檔名應該與模塊目錄名稱相同,但擴展名為 .psd1
。
注意
您無法使用變數,例如 $PSHOME
或 $HOME
,在要求輸入 Path 參數值時。 若要使用變數,請在 命令中包含 Path 參數。
類型: | String |
Position: | 1 |
預設值: | None |
必要: | True |
接受管線輸入: | False |
接受萬用字元: | False |
-PowerShellHostName
指定模組所需的 PowerShell 主機程式名稱。 輸入主機程式的名稱,例如 Windows PowerShell ISE 主機 或 ConsoleHost。 不允許通配符。
若要尋找主機程式的名稱,請在程式中輸入 $Host.Name
。
類型: | String |
Position: | Named |
預設值: | None |
必要: | False |
接受管線輸入: | False |
接受萬用字元: | False |
-PowerShellHostVersion
指定與模組搭配運作的PowerShell主機程式最低版本。 輸入版本號碼,例如 1.1。
類型: | Version |
Position: | Named |
預設值: | None |
必要: | False |
接受管線輸入: | False |
接受萬用字元: | False |
-PowerShellVersion
指定與本課程模組搭配運作的PowerShell最低版本。 例如,您可以輸入 1.0、2.0 或 3.0 做為參數的值。 它必須是 X.X 格式。 例如,如果您提交 5
,PowerShell 會擲回錯誤。
類型: | Version |
Position: | Named |
預設值: | None |
必要: | False |
接受管線輸入: | False |
接受萬用字元: | False |
-Prerelease
本模組的發行前字串。 新增發行前版本字串會將模組識別為發行前版本。 當模組發佈至 PowerShell 資源庫時,此數據會用來識別發行前版本套件。 若要從資源庫取得發行前版本套件,您必須使用 AllowPrerelease 參數搭配 PowerShellGet 命令 Find-Module
、Install-Module
、Update-Module
和 Save-Module
。
類型: | String |
Position: | Named |
預設值: | None |
必要: | False |
接受管線輸入: | False |
接受萬用字元: | False |
-PrivateData
指定匯入模組時傳遞給模組的數據。
類型: | Object |
Position: | Named |
預設值: | None |
必要: | False |
接受管線輸入: | False |
接受萬用字元: | False |
-ProcessorArchitecture
指定模組所需的處理器架構。 有效值為 x86、AMD64、IA64、MSIL 和 None(未知或未指定)。
類型: | ProcessorArchitecture |
接受的值: | None, MSIL, X86, IA64, Amd64, Arm |
Position: | Named |
預設值: | None |
必要: | False |
接受管線輸入: | False |
接受萬用字元: | False |
-ProjectUri
指定關於此項目的網頁 URL。
類型: | Uri |
Position: | Named |
預設值: | None |
必要: | False |
接受管線輸入: | False |
接受萬用字元: | False |
-ReleaseNotes
說明版本資訊。
類型: | String |
Position: | Named |
預設值: | None |
必要: | False |
接受管線輸入: | False |
接受萬用字元: | False |
-RequiredAssemblies
指定模組所需的元件 (.dll
) 檔案。 輸入元件檔名。
PowerShell 會先載入指定的元件,再更新類型或格式、匯入巢狀模組,或匯入 RootModule 索引鍵值中指定的模組檔案。
使用此參數列出模組需要的所有元件,包括需要載入的元件,以更新 FormatsToProcess 或 TypesToProcess 索引鍵中列出的任何格式或類型檔案,即便這些元件也列在 NestedModules 索引鍵中。
類型: | String[] |
Position: | Named |
預設值: | None |
必要: | False |
接受管線輸入: | False |
接受萬用字元: | False |
-RequiredModules
指定必須處於全域會話狀態的模組。 如果所需的模組不是處於全域會話狀態,PowerShell 會匯入它們。 如果無法使用所需的模組,Import-Module
命令會失敗。
輸入每個模組名稱做為字串,或輸入具有 ModuleName 和 ModuleVersion 索引鍵的哈希表。 哈希表也可以有可選的 GUID 鍵。 您可以在參數值中結合字串和哈希表。
在 PowerShell 2.0 中,Import-Module
不會自動匯入必要的模組。 它只會驗證所需的模組是否處於全域會話狀態。
類型: | Object[] |
Position: | Named |
預設值: | None |
必要: | False |
接受管線輸入: | False |
接受萬用字元: | False |
-RequireLicenseAcceptance
旗標,用於指示模組是否需要使用者在安裝、更新或儲存操作時的明確接受。
類型: | SwitchParameter |
Position: | Named |
預設值: | None |
必要: | False |
接受管線輸入: | False |
接受萬用字元: | False |
-RootModule
指定模組的主要或根檔案。 輸入腳本的檔名(.ps1
)、腳本模組(.psm1
)、模組指令清單(.psd1
)、元件(.dll
)、Cmdlet 定義 XML 檔案(.cdxml
),或工作流程(.xaml
)。 匯入模組時,從根模組檔案導出的成員會匯入呼叫端的會話狀態。
如果模組具有指令清單檔,而且 RootModule 索引鍵中未指定任何根檔案,指令清單就會成為模組的主要檔案,而模組會變成指令清單模組(ModuleType = Manifest)。
若要從具有指令清單的模組中 .psm1
或 .dll
檔案匯出成員,這些檔案的名稱必須在指令清單中的 RootModule 或 NestedModules 索引鍵的值中指定。 否則其成員不會被匯出。
注意
在 PowerShell 2.0 中,此金鑰稱為 ModuleToProcess。 您可以使用 RootModule 參數名稱或其 ModuleToProcess 別名。
類型: | String |
別名: | ModuleToProcess |
Position: | Named |
預設值: | None |
必要: | False |
接受管線輸入: | False |
接受萬用字元: | False |
-ScriptsToProcess
指定匯入模組時,在呼叫端工作階段狀態中執行的腳稿 (.ps1
) 檔案。
您可以使用這些腳本來準備環境,就像您可能使用登入腳本一樣。
若要指定在模組會話狀態中執行的腳本,請使用 NestedModules 機碼。
類型: | String[] |
Position: | Named |
預設值: | None |
必要: | False |
接受管線輸入: | False |
接受萬用字元: | False |
-Tags
指定一組標記的陣列。
類型: | String[] |
Position: | Named |
預設值: | None |
必要: | False |
接受管線輸入: | False |
接受萬用字元: | False |
-TypesToProcess
指定匯入模組時執行的類型檔案 (.ps1xml
)。
當您匯入模組時,PowerShell 會使用指定的檔案執行 Update-TypeData
Cmdlet。
因為類型檔案沒有範圍,所以會影響會話中的所有會話狀態。
類型: | String[] |
Position: | Named |
預設值: | None |
必要: | False |
接受管線輸入: | False |
接受萬用字元: | False |
-VariablesToExport
指定模組導出的變數。 允許通配符。
您可以使用此參數來限制模組所匯出的變數。 它可以從導出的變數清單中移除變數,但無法將變數新增至清單。
如果您省略此參數,New-ModuleManifest
會建立 VariablesToExport 索引鍵,其值為 *
(all),這表示模組中定義的所有變數都會由指令清單導出。
類型: | String[] |
Position: | Named |
預設值: | * (all) |
必要: | False |
接受管線輸入: | False |
接受萬用字元: | True |
-WhatIf
顯示執行 New-ModuleManifest
會發生什麼事。 這個 cmdlet 未執行。
類型: | SwitchParameter |
別名: | wi |
Position: | Named |
預設值: | False |
必要: | False |
接受管線輸入: | False |
接受萬用字元: | False |
輸入
None
您無法使用管線將物件傳送至此 cmdlet。
輸出
None
根據預設,此 Cmdlet 不會傳回任何輸出。
當您使用 PassThru 參數時,這個 Cmdlet 會傳回代表模組指令清單的字串。
備註
在 Windows 和非 Windows 平臺上執行的 New-ModuleManifest
會建立編碼為 UTF8NoBOM的模組指令清單(.psd1
)檔案。
模組指令清單通常是選擇性的。 不過,需要模組指令清單才能匯出安裝在全域程式集緩存中的元件。
若要在 $pshome\Modules
目錄中新增或變更檔案,請使用 [以 系統管理員身分執行] 選項 啟動 PowerShell。
注意
從 PowerShell 6.2 開始,PowerShell 會嘗試載入模組指令清單 FileList 屬性中列出的所有 DLL 檔案。 原生 DLL 位於 FileList 無法載入至進程中,而且錯誤會被忽略。 所有受控 DLL 都會在程序中載入。 PowerShell 7.1 已移除此行為。
在 PowerShell 2.0 中,New-ModuleManifest
的許多參數都是強制性的,即使模組指令清單中不需要這些參數也一樣。 從 PowerShell 3.0 開始,只有 Path 參數是必要的。
會話是PowerShell執行環境的實例。 會話可以有一或多個會話狀態。 根據預設,會話只有全域會話狀態,但每個匯入的模組都有自己的會話狀態。 會話狀態允許模組中的命令執行,而不會影響全域會話狀態。
呼叫者的工作階段狀態是匯入的模組所在的工作階段狀態。 一般而言,它是指全域會話狀態,但是當模組匯入巢狀模組時,呼叫端是模組,而呼叫端的會話狀態則是模組的會話狀態。