find-command powershell command

Find-Command | Taking on PowerShell one cmdlet at a time | Weekly Blog

Share this post:

This is a part of an on-going blog series written by Adam Gordon. Each week, Adam will walk you through a PowerShell command, showing you when and how to use each one. This week, Adam covers Find-Command.

When to use Find-Command

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.

 

How to use Find-Command

Find all commands in a specified repository:

Find-Command -Repository PSGallery | Select-Object -First 10

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.

Find-Command powershell command

 

Find a command by name:

Find-Command -Repository PSGallery -Name Get-TargetResource

Find-Command uses the –Repository parameter to search the PSGallery. The –Name parameter specifies the command Get-TargetResource.

Find-Command powershell command

 

Find commands by name and install the module:

Find-Command -Name Get-TargetResource -Repository PSGallery -ModuleName SystemLocaleDsc | Install-Module

Get-InstalledModule

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.

Find-Command powershell command

Find-Command powershell command

 

How to find a command and save its module:

Find-Command -Name Invoke-ScriptAnalyzer -Repository PSGallery | Save-Module -Path C:\Test\Modules -Verbose

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.

Find-Command powershell command

Find-Command powershell command

Need PowerShell training? Check out ITProTV’s PowerShell online IT training courses.

Leave a Reply

Your email address will not be published. Required fields are marked *