Home » Find Script in PowerShell

Find Script in PowerShell

The Find-Script cmdlet in PowerShell finds the script in the registered repositories. The Find-Script command is available in the PowerShellGet module.

Find-Script command without any parameters finds all available scripts in registered repositories.

Find-Script
Find Script in PowerShell
Find Script in PowerShell

In this article, we will discuss how to use the Find-Script command to find all available scripts, find a script by name, and find a script by name, and script version.

PowerShell Find-Script

Find-Script finds all available scripts in the registered repositories. You can use parameters like Name, RequiredVersion, MinimumVersion, and MaximumVersion as filters to search for scripts.

Script

Find-Script
    [[-Name] <String[]>]
    [-MinimumVersion <String>]
    [-MaximumVersion <String>]
    [-RequiredVersion <String>]
    [-AllVersions]
    [-IncludeDependencies]
    [-Filter <String>]
    [-Tag <String[]>]
    [-Includes <String[]>]
    [-Command <String[]>]
    [-Proxy <Uri>]
    [-ProxyCredential <PSCredential>]
    [-Repository <String[]>]
    [-Credential <PSCredential>]
    [-AllowPrerelease]
    [<CommonParameters>]

Let’s understand the Find-Script cmdlet with an example to search the script.

Find all Available Scripts

The Find-Script cmdlet by default search for scripts in the repositories and list all available scripts.

Find-Script | Select-Object -First 10

In the above PowerShell script, Find-Script search for scripts and piped it to the Select-Object cmdlet. The Select-Object command uses the First parameter to display first 10 results as follows.

PS C:\> Find-Script | Select-Object -First 10                                                                           
Version    Name                                Repository           Description
-------    ----                                ----------           -----------
3.5        Get-WindowsAutoPilotInfo            PSGallery            This script uses WMI to retrieve properties need...
1.1.2      Upload-WindowsAutopilotDeviceInfo   PSGallery            Gather device hash from local machine and automa...
1.7        New-OnPremiseHybridWorker           PSGallery            This Azure/OMS Automation runbook onboards a loc...
1.9        Install-VMInsights                  PSGallery            This script installs or re-configures following ...
1.7        install-kubectl                     PSGallery            This script is used during unsattended installs ...
1.0        Test-RPC                            PSGallery            This script tests TCP network connectivity to no...
5.6        Get-AutopilotDiagnostics            PSGallery            This script displays diagnostics information fro...
1.1        blah                                PSGallery            A handy function for creating a temporary array ...
1.0        SplitDbxContent                     PSGallery            Splits a DBX update package into the new DBX var...
1.1.0.12   0004-New-AzureRmVmAvailabilitySe... PSGallery            This script creates an availability set of 1-4 W...


PS C:\>                                                                                                                               

Find a Script by Name

Use the Find-Script cmdlet with the Name parameter to specify the script name. It searches for the script and returns the script information as follows.

Find-Script -Name "SpeedTest"

In the above PowerShell script, Find-Script uses the Name parameter for the script name “SpeedTest” and returns the script information as follows.


PS C:\> Find-Script -Name "SpeedTest"                                                                                   
Version    Name                                Repository           Description
-------    ----                                ----------           -----------
2.0        Speedtest                           PSGallery            WAN speed test


PS C:\>     

Find Script by Required Version and Name

Use the Find-Script cmdlet with the RequiredVersion parameter and Name parameter to specify the script details. It searches for the script in the specified repository and gets script details.

Find-Script -Name "SpeedTest" -RequiredVersion 2.0 -Repository PSGallery

In the above PowerShell script, the Find-Script uses the Name parameter to specify the script name as “SpeedTest“, the RequiredVersion parameter to specify the version as 2.0, and the Repository parameter as “PSGallery“.

The output of the above PowerShell script gets the script from the specified repository as given below.

PS C:\> Find-Script -Name "SpeedTest" -RequiredVersion 2.0 -Repository PSGallery                                        
Version    Name                                Repository           Description
-------    ----                                ----------           -----------
2.0        Speedtest                           PSGallery            WAN speed test

Conclusion

I hope the above article on how to use the Find-Script command to find the script in the repository is helpful to you.

You can find more topics about Active Directory tools and PowerShell basics on the ActiveDirectoryTools home page.

Leave a Comment