共用方式為


Find-Command

尋找模組中的 PowerShell 命令。

Syntax

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

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

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

範例

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

Cmdlet 會 Find-Command 搜尋已註冊的存放庫以取得模組。

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 會使用 存放庫 參數來指定已註冊的存放庫名稱。 物件會在管線下傳送。 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參數來搜尋PSGallery 存放庫中的命令 Invoke-ScriptAnalyzer 。 物件會向下傳送至 Save-Module 管線。 Path參數會決定儲存模組的位置。 詳細資訊 是選擇性參數,但在 PowerShell 主控台中顯示狀態輸出。 詳細資訊輸出有助於疑難排解。

參數

-AllowPrerelease

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

Type:SwitchParameter
Position:Named
Default value:None
Required:False
Accept pipeline input:False
Accept wildcard characters:False

-AllVersions

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

Type:SwitchParameter
Position:Named
Default value:None
Required:False
Accept pipeline input:False
Accept wildcard characters:False

-Filter

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

Type:String
Position:Named
Default value:None
Required:False
Accept pipeline input:False
Accept wildcard characters:False

-MaximumVersion

指定要包含在結果中的模組版本上限。 MaximumVersionRequiredVersion參數不能用在相同的命令中。

Type:String
Position:Named
Default value:None
Required:False
Accept pipeline input:False
Accept wildcard characters:False

-MinimumVersion

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

Type:String
Position:Named
Default value:None
Required:False
Accept pipeline input:False
Accept wildcard characters:False

-ModuleName

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

Type:String
Position:Named
Default value:None
Required:False
Accept pipeline input:False
Accept wildcard characters:False

-Name

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

Type:String[]
Position:0
Default value:None
Required:False
Accept pipeline input:False
Accept wildcard characters:False

-Proxy

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

Type:Uri
Position:Named
Default value:None
Required:False
Accept pipeline input:True
Accept wildcard characters:False

-ProxyCredential

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

Type:PSCredential
Position:Named
Default value:None
Required:False
Accept pipeline input:True
Accept wildcard characters:False

-Repository

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

Type:String[]
Position:Named
Default value:None
Required:False
Accept pipeline input:False
Accept wildcard characters:False

-RequiredVersion

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

Type:String
Position:Named
Default value:None
Required:False
Accept pipeline input:False
Accept wildcard characters:False

-Tag

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

Type:String[]
Position:Named
Default value:None
Required:False
Accept pipeline input:False
Accept wildcard characters:False

輸出

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 部落格中的公告 \(英文\)。