Powershell

How to Use the Find-Command (PowerShellGet) Cmdlet in PowerShell?

PowerShell’s “Find-Command” cmdlet is used to find the commands, such as functions, aliases, and workflows. Moreover, it is used to search modules inside the registered repositories. Each command that is found by the stated cmdlet, returns the “PSGetCommandInfo” object.

This post will overview PowerShell’s “Find-Command” cmdlet in-depth.

How to Use the Find-Command (PowerShellGet) Cmdlet in PowerShell?

To find commands from the module, first, specify the “Find-Command” cmdlet. Then, place the “-Repository” parameter and assign it the repository name to find the commands inside it. To do so, check out the given examples.

Example 1: Use the “Find-Command” Cmdlet to List all the Command From the Specified Directory
First, place the “Find-Command” cmdlet, along with the “-Repository” parameter, and assign it to the repository name whose commands need to be retrieved:

Find-Command -Repository PSGallery

Example 2: Use the “Find-Command” Cmdlet to Find the First Five Commands
Execute the following cmdlet to retrieve only the first five commands from the desired repository:

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

Here:

  • First, specify the “Find-Command” command along with the “-Repository” parameter and its value. Then, pipe it to the “Select-Object” cmdlet to select a certain number of commands.
  • After that, write the “-First” parameter and specify the value “5” to only display the first five commands:

Example 3: Use the “Find-Command” Cmdlet to Retrieve a Particular Command Detail by its Name
To find the detail of the command by name, use the “-Name” parameter and specify its name:

Find-Command -Repository PSGallery -Name Get-WUHistory

Example 4: Use the “Find-Command” Cmdlet to Find a Command by Name and Install a Module
Run the following cmdlet to find the command by name and then install a module:

Find-Command -Repository PSGallery -Name Get-WUHistory -ModuleName PSWindowsUpdate | Install-Module

According to the above-given command:

  • First, write the command to find a cmdlet by name.
  • Then, use the “-ModuleName” parameter to specify a module name and pipe it to the “Install-Module” cmdlet to install the module:

That’s all! You have successfully learned about the “Find-Command” in PowerShell.

Conclusion

The “Find-Command” cmdlet is used to search the PowerShell commands that are available in modules. However, it only searches commands from the registered repositories in PowerShell. This tutorial has covered the aspects explaining the “Find-Command” cmdlet to find the commands in PowerShell.

About the author

Muhammad Farhan

I am a Computer Science graduate and now a technical writer who loves to provide the easiest solutions to the most difficult problems related to Windows, Linux, and Web designing. My love for Computer Science emerges every day because of its ease in our everyday life.