Find-Command

Finds PowerShell commands in modules.

语法

All

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

说明

The Find-Command cmdlet finds PowerShell commands such as cmdlets, aliases, functions, and workflows. Find-Command searches modules in registered repositories.

For each command found by Find-Command, a PSGetCommandInfo object is returned. The PSGetCommandInfo object can be sent down the pipeline to the Install-Module cmdlet. Install-Module installs the module that contains the command.

示例

Example 1: Find all commands in a specified repository

The Find-Command cmdlet searches a registered repository for modules.

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 uses the Repository parameter to specify a registered repository's name. The objects are sent down the pipeline. Select-Object receives the objects and uses the First parameter to display the first 10 results.

Example 2: Find a command by name

Find-Command can use the name of a command to locate the module in a repository. It's possible that a command name exists in multiple 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 uses the Repository parameter to search the PSGallery. The Name parameter specifies the command Get-TargetResource.

Example 3: Find commands by name and install the module

Find-Command can locate the command and module, then send the object to Install-Module. If a command is included in multiple modules, use the Find-Command cmdlets Module-Name parameter. Otherwise, modules might be installed that you didn't want to install.

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 uses the Name parameter to specify the command Get-TargetResource. The Repository parameter searches the PSGallery. The ModuleName parameter specifies the module you want to install, SystemLocaleDsc. The object is sent down the pipeline to Install-Module and the module is installed. After the installation finishes, you can use Get-InstalledModule to display the results.

Example 4: Find a command and save its module

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 uses the Name and Repository parameters to search for the command Invoke-ScriptAnalyzer in the PSGallery repository. The object is sent down the pipeline to Save-Module. The Path parameter determines the location to save the module. Verbose is an optional parameter, but displays status output in the PowerShell console. The verbose output is beneficial for troubleshooting.

参数

-AllVersions

Indicates that this cmdlet gets all versions of a module.

参数属性

类型:SwitchParameter
默认值:None
支持通配符:False
不显示:False

参数集

(All)
Position:Named
必需:False
来自管道的值:False
来自管道的值(按属性名称):False
来自剩余参数的值:False

-Filter

Finds modules based on the PackageManagement provider's search syntax. For example, specify words to search for within the ModuleName and Description properties.

参数属性

类型:String
默认值:None
支持通配符:False
不显示:False

参数集

(All)
Position:Named
必需:False
来自管道的值:False
来自管道的值(按属性名称):False
来自剩余参数的值:False

-MaximumVersion

Specifies the maximum version of the module to include in results. The MaximumVersion and the RequiredVersion parameters can't be used in the same command.

参数属性

类型:Version
默认值:None
支持通配符:False
不显示:False

参数集

(All)
Position:Named
必需:False
来自管道的值:False
来自管道的值(按属性名称):False
来自剩余参数的值:False

-MinimumVersion

Specifies the minimum version of the module to include in results. The MinimumVersion and the RequiredVersion parameters can't be used in the same command.

参数属性

类型:Version
默认值:None
支持通配符:False
不显示:False

参数集

(All)
Position:Named
必需:False
来自管道的值:False
来自管道的值(按属性名称):False
来自剩余参数的值:False

-ModuleName

Specifies the name of a module to search for commands. The default is all modules.

参数属性

类型:String
默认值:None
支持通配符:False
不显示:False

参数集

(All)
Position:Named
必需:False
来自管道的值:False
来自管道的值(按属性名称):False
来自剩余参数的值:False

-Name

Specifies the command name to search for in a repository. Use commas to separate an array of command names.

参数属性

类型:

String[]

默认值:None
支持通配符:False
不显示:False

参数集

(All)
Position:0
必需:False
来自管道的值:False
来自管道的值(按属性名称):False
来自剩余参数的值:False

-Proxy

Specifies a proxy server for the request, rather than a direct connection to the internet resource.

参数属性

类型:Uri
默认值:None
支持通配符:False
不显示:False

参数集

(All)
Position:Named
必需:False
来自管道的值:False
来自管道的值(按属性名称):True
来自剩余参数的值:False

-ProxyCredential

Specifies a user account that has permission to use the proxy server that is specified by the Proxy parameter.

参数属性

类型:PSCredential
默认值:None
支持通配符:False
不显示:False

参数集

(All)
Position:Named
必需:False
来自管道的值:False
来自管道的值(按属性名称):True
来自剩余参数的值:False

-Repository

Specifies the repository to search for commands. Use commas to separate an array of repository names. The default is all repositories.

参数属性

类型:

String[]

默认值:None
支持通配符:False
不显示:False

参数集

(All)
Position:Named
必需:False
来自管道的值:False
来自管道的值(按属性名称):False
来自剩余参数的值:False

-RequiredVersion

Specifies the version of the module to include in the results.

参数属性

类型:Version
默认值:None
支持通配符:False
不显示:False

参数集

(All)
Position:Named
必需:False
来自管道的值:False
来自管道的值(按属性名称):False
来自剩余参数的值:False

-Tag

Specifies tags that categorize modules in a repository. Use commas to separate an array of tags.

参数属性

类型:

String[]

默认值:None
支持通配符:False
不显示:False

参数集

(All)
Position:Named
必需:False
来自管道的值:False
来自管道的值(按属性名称):False
来自剩余参数的值:False

CommonParameters

This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutBuffer, -OutVariable, -PipelineVariable, -ProgressAction, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters.

输出

PSGetCommandInfo

Find-Command outputs a PSGetCommandInfo object.