Find-Command
在模块中查找 PowerShell 命令。
语法
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>]
说明
该 Find-Command
cmdlet 查找 PowerShell 命令,例如 cmdlet、别名、函数和工作流。
Find-Command
在已注册的存储库中搜索模块。
这是 Microsoft.PowerShell.PSResourceGet 中 cmdlet 的代理 cmdletFind-PSResource
。 有关详细信息,请参阅 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
使用 存储库 参数搜索 PSGallery。
Name 参数指定命令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
。
存储库参数搜索 PSGallery。
ModuleName 参数指定要安装的模块 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
使用 Name 和 Repository 参数搜索 PSGallery 存储库中的命令Invoke-ScriptAnalyzer
。 将对象向下发送到管道 Save-Module
。
Path 参数确定保存模块的位置。
详细 是可选参数,但在 PowerShell 控制台中显示状态输出。 详细输出有利于故障排除。
参数
-AllowPrerelease
在结果中包含标记为预发行版的模块。
代理 cmdlet 将此参数映射到 预发行版 参数 Find-PSResource
。
类型: | SwitchParameter |
Position: | Named |
默认值: | None |
必需: | False |
接受管道输入: | False |
接受通配符: | False |
-AllVersions
代理 cmdlet 忽略此参数,因为 CommandNameParameterSet 不支持 Find-PSResource
此参数。
类型: | SwitchParameter |
Position: | Named |
默认值: | None |
必需: | False |
接受管道输入: | False |
接受通配符: | False |
-Filter
代理 cmdlet 忽略此参数,因为 CommandNameParameterSet 不支持 Find-PSResource
此参数。
类型: | String |
Position: | Named |
默认值: | None |
必需: | False |
接受管道输入: | False |
接受通配符: | False |
-MaximumVersion
代理 cmdlet 忽略此参数,因为 CommandNameParameterSet 不支持 Find-PSResource
此参数。
类型: | String |
Position: | Named |
默认值: | None |
必需: | False |
接受管道输入: | False |
接受通配符: | False |
-MinimumVersion
代理 cmdlet 忽略此参数,因为 CommandNameParameterSet 不支持 Find-PSResource
此参数。
类型: | String |
Position: | Named |
默认值: | None |
必需: | False |
接受管道输入: | False |
接受通配符: | False |
-ModuleName
代理 cmdlet 忽略此参数,因为 CommandNameParameterSet 不支持 Find-PSResource
此参数。
类型: | String |
Position: | Named |
默认值: | None |
必需: | False |
接受管道输入: | False |
接受通配符: | False |
-Name
指定要在存储库中搜索的命令名称。 使用逗号分隔命令名称数组。
代理 cmdlet 将此参数映射到 . 的 Find-PSResource
CommandName 参数。
类型: | String[] |
Position: | 0 |
默认值: | None |
必需: | False |
接受管道输入: | False |
接受通配符: | False |
-Proxy
代理 cmdlet 忽略此参数,因为 CommandNameParameterSet 不支持 Find-PSResource
此参数。
类型: | Uri |
Position: | Named |
默认值: | None |
必需: | False |
接受管道输入: | True |
接受通配符: | False |
-ProxyCredential
代理 cmdlet 忽略此参数,因为 CommandNameParameterSet 不支持 Find-PSResource
此参数。
类型: | PSCredential |
Position: | Named |
默认值: | None |
必需: | False |
接受管道输入: | True |
接受通配符: | False |
-Repository
指定要搜索命令的存储库。 使用逗号分隔存储库名称数组。 默认值为所有存储库。
类型: | String[] |
Position: | Named |
默认值: | None |
必需: | False |
接受管道输入: | False |
接受通配符: | False |
-RequiredVersion
代理 cmdlet 忽略此参数,因为 CommandNameParameterSet 不支持 Find-PSResource
此参数。
类型: | String |
Position: | Named |
默认值: | None |
必需: | False |
接受管道输入: | False |
接受通配符: | False |
-Tag
代理 cmdlet 忽略此参数,因为 CommandNameParameterSet 不支持 Find-PSResource
此参数。
类型: | String[] |
Position: | Named |
默认值: | None |
必需: | False |
接受管道输入: | False |
接受通配符: | False |
输出
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