共用方式為


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-PSResource 中 Cmdlet 的 Proxy Cmdlet。 如需詳細資訊,請參閱 Find-PSResource

範例

範例 1:依名稱尋找命令

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

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

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

Find-Command -Name Get-TargetResource -Repository PSGallery -ModuleName SystemLocaleDsc |
    Install-Module
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 來顯示結果。

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

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

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

Proxy Cmdlet 會將此參數對應至 的Find-PSResource參數。

參數屬性

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

參數集

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

-AllVersions

Proxy Cmdlet 會忽略此參數,因為 的 CommandNameParameterSetFind-PSResource不支援此參數。

參數屬性

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

參數集

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

-Filter

Proxy Cmdlet 會忽略此參數,因為 的 CommandNameParameterSetFind-PSResource不支援此參數。

參數屬性

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

參數集

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

-MaximumVersion

Proxy Cmdlet 會忽略此參數,因為 的 CommandNameParameterSetFind-PSResource不支援此參數。

參數屬性

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

參數集

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

-MinimumVersion

Proxy Cmdlet 會忽略此參數,因為 的 CommandNameParameterSetFind-PSResource不支援此參數。

參數屬性

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

參數集

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

-ModuleName

Proxy Cmdlet 會忽略此參數,因為 的 CommandNameParameterSetFind-PSResource不支援此參數。

參數屬性

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

參數集

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

-Name

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

Proxy Cmdlet 會將此參數對應至 的 Find-PSResource 參數。

參數屬性

類型:

String[]

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

參數集

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

-Proxy

Proxy Cmdlet 會忽略此參數,因為 的 CommandNameParameterSetFind-PSResource不支援此參數。

參數屬性

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

參數集

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

-ProxyCredential

Proxy Cmdlet 會忽略此參數,因為 的 CommandNameParameterSetFind-PSResource不支援此參數。

參數屬性

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

參數集

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

-Repository

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

參數屬性

類型:

String[]

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

參數集

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

-RequiredVersion

Proxy Cmdlet 會忽略此參數,因為 的 CommandNameParameterSetFind-PSResource不支援此參數。

參數屬性

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

參數集

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

-Tag

Proxy Cmdlet 會忽略此參數,因為 的 CommandNameParameterSetFind-PSResource不支援此參數。

參數屬性

類型:

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 物件。

備註

PowerShell 資源庫不再支援傳輸層安全性 (TLS) 1.0 和 1.1 版。 您必須使用 TLS 1.2 或更高版本。 使用下列命令以確保您使用 TLS 1.2:

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