Get-Command in PowerShell

📜Part of the PowerShell Complete Guide, every PowerShell post on this site, grouped by the job you are doing.

Get-Command is a cmdlet in PowerShell that lets you retrieve a list of all available commands in your current session. It’s a go-to tool for discovering new commands and understanding their usage and capabilities.


Filtering with Wildcards

You can use Get-Command with wildcards to filter results based on patterns. This is particularly useful when you’re not sure of a command’s exact name but know part of it.

PowerShell
# get-command, better use wildcards *
Get-Command test-sql*
PowerShell Get Command Wildcard

We can list commands that belong to a specific PowerShell module, or that have a specific verb or noun in their name. For example, run Get-Command Test-* to retrieve all PowerShell cmdlets with the ‘Test’ prefix.

Put the wildcard on the verb side to find every command for one noun. -Syntax then shows the parameter sets of a single command, which is quicker than opening the help:

PowerShell
# every command with the Service noun
Get-Command *-Service

# the parameter sets for one command
Get-Command Get-Service -Syntax
PowerShell 7: Get-Command *-Service lists nine cmdlets from Get-Service to Suspend-Service, version 7.0.0.0 from Microsoft.PowerShell.Management, and Get-Command Get-Service -Syntax shows its three parameter sets

This was just a quick post / note of a SQL PowerShell get-command cmdlet example. Hope it was useful!

If SQL Server is part of your day job, my current work lives over at sqldba.blog: production DBA scripts, an error library and the SSMS guide.

Comments

Leave a Reply

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