共用方式為


Find-Command

在模組中尋找 PowerShell 命令。

語法

All

Find-Command
    [[-Name] <String[]>]
    [-ModuleName <String>]
    [-MinimumVersion <String>]
    [-MaximumVersion <String>]
    [-RequiredVersion <String>]
    [-AllVersions]
    [-AllowPrerelease]
    [-Tag <String[]>]
    [-Filter <String>]
    [-Proxy <Uri>]
    [-ProxyCredential <PSCredential>]
    [-Repository <String[]>]
    [<CommonParameters>]

Description

Find-Command Cmdlet 會尋找 PowerShell 命令,例如 Cmdlet、別名、函式和工作流程。 Find-Command 搜尋已註冊存放庫中的模組。

針對 Find-Command找到的每個命令,會傳回 PSGetCommandInfo 物件。 PSGetCommandInfo 物件可以向下傳送至 Install-Module Cmdlet。 Install-Module 安裝包含 命令的模組。

範例

範例 1:尋找指定存放庫中的所有命令

Find-Command Cmdlet 會搜尋已註冊的存放庫來尋找模組。

Find-Command -Repository PSGallery | Select-Object -First 10
Name                                Version    ModuleName          Repository
----                                -------    ----------          ----------
Disable-AzureRmDataCollection       5.8.3      AzureRM.profile     PSGallery
Disable-AzureRmContextAutosave      5.8.3      AzureRM.profile     PSGallery
Enable-AzureRmDataCollection        5.8.3      AzureRM.profile     PSGallery
Enable-AzureRmContextAutosave       5.8.3      AzureRM.profile     PSGallery
Remove-AzureRmEnvironment           5.8.3      AzureRM.profile     PSGallery
Get-AzureRmEnvironment              5.8.3      AzureRM.profile     PSGallery
Set-AzureRmEnvironment              5.8.3      AzureRM.profile     PSGallery
Add-AzureRmEnvironment              5.8.3      AzureRM.profile     PSGallery
Get-AzureRmSubscription             5.8.3      AzureRM.profile     PSGallery
Connect-AzureRmAccount              5.8.3      AzureRM.profile     PSGallery

Find-Command 會使用 Repository 參數來指定已註冊的存放庫名稱。 物件會在管線下傳送。 Select-Object 會接收 物件,並使用 First 參數來顯示前 10 個結果。

範例 2:依名稱尋找命令

Find-Command 可以使用命令的名稱,在存放庫中尋找模組。 命令名稱可能存在於多個 ModuleNames中。

Find-Command -Repository PSGallery -Name Get-TargetResource
Name                  Version    ModuleName                      Repository
----                  -------    ----------                      ----------
Get-TargetResource    3.1.0.0    xPowerShellExecutionPolicy      PSGallery
Get-TargetResource    1.0.0      xInternetExplorerHomePage       PSGallery
Get-TargetResource    1.2.0.0    SystemLocaleDsc                 PSGallery

Find-Command 會使用 Repository 參數來搜尋 PSGalleryName 參數會指定命令 Get-TargetResource

範例 3:依名稱尋找命令並安裝模組

Find-Command 可以找到 命令和模組,然後將 物件傳送至 Install-Module。 如果命令包含在多個模組中,請使用 Find-Command Cmdlets ModuleName 參數。 否則,可能會安裝您不想安裝的模組。

PS> Find-Command -Name Get-TargetResource -Repository PSGallery -ModuleName SystemLocaleDsc |
    Install-Module

PS> Get-InstalledModule

Version   Name               Repository   Description
-------   ----               ----------   -----------
1.2.0.0   SystemLocaleDsc    PSGallery    This DSC Resource allows configuration of the Windows...

Find-Command 使用 Name 參數來指定指令 Get-TargetResource存放庫 參數會搜尋 PSGalleryModuleName 參數會指定您要安裝的模組,SystemLocaleDsc。 物件會向下傳送至管線,以 Install-Module 並安裝模組。 安裝完成之後,您可以使用 Get-InstalledModule 來顯示結果。

範例 4:尋找命令並儲存其模組

PS> Find-Command -Name Invoke-ScriptAnalyzer -Repository PSGallery | Save-Module -Path C:\Test\Modules -Verbose

VERBOSE: Downloading 'https://www.powershellgallery.com/api/v2/package/PSScriptAnalyzer/1.18.0'.
VERBOSE: Completed downloading 'https://www.powershellgallery.com/api/v2/package/PSScriptAnalyzer/1.18.0'.
VERBOSE: Completed downloading 'PSScriptAnalyzer'.
VERBOSE: Module 'PSScriptAnalyzer' was saved successfully to path 'C:\Test\Modules\PSScriptAnalyzer\1.18.0'.

Find-Command會使用 NameRepository 參數來搜尋 Invoke-ScriptAnalyzer 存放庫中的命令。 物件會從管線向下傳送至 Save-ModulePath 參數會決定儲存模組的位置。 詳細資訊 是選擇性參數,但在PowerShell控制台中顯示狀態輸出。 詳細信息輸出有助於疑難解答。

參數

-AllowPrerelease

在結果中包含標示為發行前版本的模組。

參數屬性

類型:SwitchParameter
預設值:None
支援萬用字元:False
不要顯示:False

參數集

(All)
Position:Named
必要:False
來自管線的值:False
來自管線按屬性名稱的值:False
來自剩餘引數的值:False

-AllVersions

指出此 Cmdlet 會取得模組的所有版本。

參數屬性

類型:SwitchParameter
預設值:None
支援萬用字元:False
不要顯示:False

參數集

(All)
Position:Named
必要:False
來自管線的值:False
來自管線按屬性名稱的值:False
來自剩餘引數的值:False

-Filter

根據 PackageManagement 提供者的搜尋語法來尋找模組。 例如,指定要在 ModuleName 內搜尋的字組,並 Description 屬性。

參數屬性

類型:String
預設值:None
支援萬用字元:False
不要顯示:False

參數集

(All)
Position:Named
必要:False
來自管線的值:False
來自管線按屬性名稱的值:False
來自剩餘引數的值:False

-MaximumVersion

指定要包含在結果中的模組最大版本。 MaximumVersionRequiredVersion 參數不能在同一個命令中使用。

參數屬性

類型:String
預設值:None
支援萬用字元:False
不要顯示:False

參數集

(All)
Position:Named
必要:False
來自管線的值:False
來自管線按屬性名稱的值:False
來自剩餘引數的值:False

-MinimumVersion

指定要包含在結果中的模組最低版本。 MinimumVersionRequiredVersion 參數不能在同一個命令中使用。

參數屬性

類型:String
預設值:None
支援萬用字元:False
不要顯示:False

參數集

(All)
Position:Named
必要:False
來自管線的值:False
來自管線按屬性名稱的值:False
來自剩餘引數的值:False

-ModuleName

指定要搜尋命令的模組名稱。 預設值為所有模組。

參數屬性

類型:String
預設值:None
支援萬用字元:False
不要顯示:False

參數集

(All)
Position:Named
必要:False
來自管線的值:False
來自管線按屬性名稱的值:False
來自剩餘引數的值:False

-Name

指定要在存放庫中搜尋的命令名稱。 使用逗號分隔命令名稱的陣列。

參數屬性

類型:

String[]

預設值:None
支援萬用字元:False
不要顯示:False

參數集

(All)
Position:0
必要:False
來自管線的值:False
來自管線按屬性名稱的值:False
來自剩餘引數的值:False

-Proxy

指定要求的 Proxy 伺服器,而不是直接連線到因特網資源。

參數屬性

類型:Uri
預設值:None
支援萬用字元:False
不要顯示:False

參數集

(All)
Position:Named
必要:False
來自管線的值:False
來自管線按屬性名稱的值:True
來自剩餘引數的值:False

-ProxyCredential

指定有權使用 Proxy 參數所指定 Proxy 伺服器的用戶帳戶。

參數屬性

類型:PSCredential
預設值:None
支援萬用字元:False
不要顯示:False

參數集

(All)
Position:Named
必要:False
來自管線的值:False
來自管線按屬性名稱的值:True
來自剩餘引數的值:False

-Repository

指定要搜尋命令的存放庫。 使用逗號分隔存放庫名稱的陣列。 預設值為所有存放庫。

參數屬性

類型:

String[]

預設值:None
支援萬用字元:False
不要顯示:False

參數集

(All)
Position:Named
必要:False
來自管線的值:False
來自管線按屬性名稱的值:False
來自剩餘引數的值:False

-RequiredVersion

指定要包含在結果中的模組版本。

參數屬性

類型:String
預設值:None
支援萬用字元:False
不要顯示:False

參數集

(All)
Position:Named
必要:False
來自管線的值:False
來自管線按屬性名稱的值:False
來自剩餘引數的值:False

-Tag

指定將存放庫中模組分類的標記。 使用逗號分隔標記陣列。

參數屬性

類型:

String[]

預設值:None
支援萬用字元:False
不要顯示:False

參數集

(All)
Position:Named
必要:False
來自管線的值:False
來自管線按屬性名稱的值:False
來自剩餘引數的值:False

CommonParameters

此 Cmdlet 支援一般參數:-Debug、-ErrorAction、-ErrorVariable、-InformationAction、-InformationVariable、-OutBuffer、-OutVariable、-PipelineVariable、-ProgressAction、-Verbose、-WarningAction 和 -WarningVariable。 如需詳細資訊,請參閱 about_CommonParameters

輸出

PSGetCommandInfo

Find-Command 輸出 PSGetCommandInfo 物件。

備註

這很重要

自 2020 年 4 月起,PowerShell 資源庫不再支援傳輸層安全性 (TLS) 1.0 和 1.1 版。 如果您未使用 TLS 1.2 或更高版本,當您嘗試存取 PowerShell 資源庫時,會收到錯誤。 使用下列命令以確保您使用 TLS 1.2:

[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12

如需詳細資訊,請參閱 PowerShell 部落格中的 公告