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