取得已匯入或可匯入至目前工作階段的模組。
語法
Get-Module [-All] [-ListAvailable] [-Name <string[]>] [<CommonParameters>] Get-Module [[-Name] <string[]>] [<CommonParameters>]
描述
Get-Module Cmdlet 會取得已匯入或可匯入至此工作階段的模組。
Get-Module 只會取得模組,但無法匯入模組。若要將模組匯入至工作階段,請使用 Import-Module。
參數
-All
取得所有模組檔案的模組物件。
如果沒有使用 All 參數,Get-Module 只會取得預設模組檔案的模組物件。此 Cmdlet 會依照下列順序選取檔案類型:資訊清單 (.psd1) 檔案、指令碼模組 (.psm1) 檔案和二進位模組 (.dll) 檔案。
必要? |
false |
位置? |
named |
預設值 |
|
接受管線輸入? |
false |
接受萬用字元? |
false |
-ListAvailable
取得所有可匯入至此工作階段的模組。Get-Module 會取得 $env:PSModulePath 環境變數所指定之路徑中的模組。
如果未指定這個參數,Get-Module 只會取得已匯入至此工作階段的模組。
必要? |
false |
位置? |
named |
預設值 |
|
接受管線輸入? |
false |
接受萬用字元? |
false |
-Name <string[]>
只取得具有指定之名稱或名稱模式的模組。允許使用萬用字元。您也可以經由管道將名稱輸出至 Get-Module。
必要? |
false |
位置? |
1 |
預設值 |
All imported or available modules. |
接受管線輸入? |
true (ByValue) |
接受萬用字元? |
true |
<CommonParameters>
這個 Cmdlet 支援一般參數:-Verbose、-Debug、-ErrorAction、-ErrorVariable、-OutBuffer 和 -OutVariable。如需詳細資訊,請參閱 about_Commonparameters.
輸入和輸出
輸入型別是可經由管道輸出至 Cmdlet 的物件型別。傳回型別則是 Cmdlet 所傳回的物件型別。
輸入 |
System.String 您可經由管道將模組名稱輸出至 Get-Module。 |
輸出 |
System.Management.Automation.PSModuleInfo Get-Module 會傳回代表模組的物件。 |
附註
您也可以利用 Get-Module 的別名 ("gmo") 來表示此 Cmdlet。如需詳細資訊,請參閱 about_Aliases。
All 參數會傳回副檔名為 .dll 之所有檔案的模組物件,即使這些檔案沒有實作 Cmdlet 或提供者也一樣。
範例 1
C:\PS>get-module 描述 ----------- 這個命令會取得已匯入至目前工作階段的模組。
範例 2
C:\PS>get-module -listAvailable 描述 ----------- 這個命令會取得可匯入至目前工作階段的模組。 Get-Module 會在 $env:PSModulePath 環境變數所指定的路徑中尋找可用的模組。如需 PSModulePath 的詳細資訊,請參閱 about_Modules 和 about_Environment_Variables。
範例 3
C:\PS>get-module -listAvailable -all 描述 ----------- 這個命令會取得所有可用模組之所有匯出的檔案。
範例 4
C:\PS>get-module | get-member -type property TypeName: System.Management.Automation.PSModuleInfo Name MemberType Definition ---- ---------- ---------- AccessMode Property System.Management.Automation.ModuleAcc Description Property System.String Description {get;set;} ExportedAliases Property System.Collections.Generic.Dictionary` ExportedCmdlets Property System.Collections.Generic.Dictionary` ExportedFunctions Property System.Collections.Generic.Dictionary` ExportedVariables Property System.Collections.Generic.Dictionary` Guid Property System.Guid Guid {get;} ModuleBase Property System.String ModuleBase {get;} ModuleType Property System.Management.Automation.ModuleTyp Name Property System.String Name {get;} NestedModules Property System.Collections.ObjectModel.ReadOnl OnRemove Property System.Management.Automation.ScriptBlo Path Property System.String Path {get;} PrivateData Property System.Object PrivateData {get;set;} SessionState Property System.Management.Automation.SessionSt Version Property System.Version Version {get;} 描述 ----------- 這個命令會取得 Get-Module 傳回之 PSModuleInfo 物件的屬性。每個模組檔案都有一個代表物件。 您可以使用這些屬性,格式化及篩選模組物件。如需這些屬性的詳細資訊,請參閱 MSDN (Microsoft Developer Network) Library 中的<PSModule 屬性>(英文),網址為:https://go.microsoft.com/fwlink/?LinkId=143624。
範例 5
C:\PS>get-module -listAvailable -all | format-table -property name, moduletype, path -groupby name -auto Name: MyTestCmdlets Name ModuleType Path ---- ---------- ---- MyTestCmdlets Script C:\Windows\system32\WindowsPowerShell\v1.0\Modules\TestCmdlets\TestCmdlets.dll Name: PSDiagnostics Name ModuleType Path ---- ---------- ---- PSDiagnostics Manifest C:\Windows\system32\WindowsPowerShell\v1.0\Modules\PSDiagnostics\PSDiagnostics.psd1 PSDiagnostics Script C:\Windows\system32\WindowsPowerShell\v1.0\Modules\PSDiagnostics\PSDiagnostics.psm1 Name: FileTransfer Name ModuleType Path ---- ---------- ---- FileTransfer Manifest C:\Windows\system32\WindowsPowerShell\v1.0\Modules\FileTransfer\FileTransfer.psd1 描述 ----------- 這個命令會取得所有模組檔案 (已匯出和可用的檔案) 並依模組名稱來分組。如此一來,您就能查看每個指令碼要匯出的模組檔案。
範例 6
C:\PS>$m = get-module -list -name FileTransfer | where {$_.moduletype -eq "Manifest"} C:\PS> get-content $m.path @{ GUID="{8FA5064B-8479-4c5c-86EA-0D311FE48875}" Author="Microsoft Corporation" CompanyName="Microsoft Corporation" Copyright="© Microsoft Corporation. All rights reserved." ModuleVersion="1.0.0.0" Description="Windows Powershell File Transfer Module" PowerShellVersion="2.0" CLRVersion="2.0" NestedModules="Microsoft.BackgroundIntelligentTransfer.Management" FormatsToProcess="FileTransfer.Format.ps1xml" RequiredAssemblies=Join-Path $psScriptRoot "Microsoft.BackgroundIntelligentTransfer.Management.Interop.dll" } 描述 ----------- 這些命令會顯示 Windows PowerShell 檔案傳輸模組的模組資訊清單內容。 第一個命令會取得 PSModuleInfo 物件,此物件表示檔案傳輸模組的模組資訊清單。這個命令會將該物件儲存在 $m 變數中。 第二個命令會使用點標記法,取得儲存在物件之 Path 屬性中資訊清單檔案的路徑。然後,再使用 Get-Content Cmdlet 取得指定路徑中資訊清單檔案的內容。 模組不需要具有資訊清單檔案。當它們具有資訊清單檔案時,資訊清單只需要包含版本號碼。不過,資訊清單檔案通常會提供模組、其需求及其內容的有用資訊。
範例 7
C:\PS>get-module -listAvailable -name FileTransfer | format-list -property * Name : FileTransfer Path : C:\Windows\system32\WindowsPowerShell\v1.0\Modules\FileTransfer\FileTransfer.psd1 Description : Powershell File Transfer Module Guid : 8fa5064b-8479-4c5c-86ea-0d311fe48875 ModuleBase : C:\Windows\system32\WindowsPowerShell\v1.0\Modules\FileTransfer PrivateData : Version : 1.0.0.0 ModuleType : Manifest AccessMode : ReadWrite ExportedFunctions : {} ExportedCmdlets : {} NestedModules : {} ExportedVariables : {} ExportedAliases : {} SessionState : System.Management.Automation.SessionState OnRemove : 描述 ----------- 這個命令會在清單中顯示 FileTransfer 模組的所有屬性。 因為尚未將此模組匯入至工作階段,所以尚未填入 Exported* 屬性和 NestedModules 屬性。只有在匯出這些元素並已將巢狀模組具現化之後,才會填入這些屬性。
範例 8
C:\PS>dir (get-module -listavailable FileTransfer).modulebase Directory: C:\Windows\system32\WindowsPowerShell\v1.0\Modules\FileTransfer Mode LastWriteTime Length Name ---- ------------- ------ ---- d---- 12/16/2008 12:36 PM en-US -a--- 11/19/2008 11:30 PM 16184 FileTransfer.Format.ps1xml -a--- 11/20/2008 11:30 PM 1044 FileTransfer.psd1 -a--- 12/16/2008 12:20 AM 108544 Microsoft.BackgroundIntelligentTransfer.Management.Interop.dll 描述 ----------- 這個命令會列出模組目錄中的檔案。這是匯入模組之前判斷模組內容的另一個方法。某些模組可能有描述本身的說明檔案或讀我檔案。
請參閱