Taking on PowerShell one cmdlet at a time

Share this post:This blog post is part of an ongoing series by Adam Gordon. Adam will show you how to use each PowerShell command each week. Adam will be covering Find-Command this week.

When to use Find Command
The Find-Command cmdlet searches PowerShell commands like cmdlets, aliases and functions. Find-Command searches modules within registered repositories.
A PSGetCommandInfo object returns each command that Find-Command finds. The PSGetCommandInfo object is available for sending down the pipeline to Install-Module cmdlet. Install-Module installs a module that contains the command.

How to use Find-Command
Find all commands in a given repository:
Select-Object -First 10
Find-Command uses a parameter called -Repository to identify a registered repository. The objects are sent through the pipeline. Select-Object receives the objects. It uses the -First parameter for the first 10 results.

Search for a command by name
Locate-Command -Repository PSGallery Name Get-TargetResource
Find-Command uses a -Repository parameter for searching the PSGallery. The -Name parameter specifies Get-TargetResource.

Locate commands by name and install them:
Find-Command uses a -Name parameter to specify Get-TargetResource.
The -Repository parameter searches PSGallery. The -ModuleName parameter specifies which module you want to install, SystemLocaleDsc.
The object is sent to Install-Module, and the module is then installed.
You can display the results by using Get-InstalledModule after the installation is complete.

How to locate a command and save it as a 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 to Save-Module. The -Path parameter specifies the location where the module will be saved.
-Verbose can be used as an optional parameter. However, it displays the status output in PowerShell console. Troubleshooting is easier with the verbose output.

Learn the command For-EachObject from last week.
Do you need PowerShell training? ITProTV offers PowerShell online IT training courses.

Previous post Alexa, Are You Listening?
Next post Taking on PowerShell one cmdlet at a time