PowerShell’s Show-Command | The Best Visual Alternative To Scripting

A person discovering how good Show-Command truly is
This is you after finding this trick!

Today, we’re going to take a quick look into the Show-Command utility built into the Windows version of PowerShell

Before we jump into the use cases, lets go over some surface level stuff!

I also posted this on Medium, in case you prefer reading it over there!

Show-Command Aliases

Currently, you can use shcm as an alias for the Show-Command utility.

Limitations

Show-Command is only available on the Windows platform. So PowerShell for Linux installs won’t have this utility. Sorry!

Description

The Show-Command cmdlet allows you to use any PowerShell command in a graphical window. This allows you to learn command faster as you can see the parameters graphically versus pressing the Shift key multiple times to cycle through the options.

The Show-Command utility was introduced in PowerShell version 7.

Lets Jump In!

Okay, let me show you the simplest example that I can think of. If you were to run:

Show-Command Test-NetConnection

You would get this popup:

Show-Command on the Test-NetConnection command
The Show-Command utility with Test-NetConnection

I hope you can see how this would certainly be useful. Having a graphical input and dropdown menus make learning and debugging commands so much easier.

The window is also resizable and includes the most command parameters for whatever command you use the Show-Command utility on. You can see that I’ve opened the Command Parameters section in the above screenshot to show off this use case.

What’s fairly weird about the Show-Command utility, and PowerShell in general, is that there doesn’t seem to be a single syntax option for running a command. You’ve seen me complain about this before, in my recent post where I complained about the built-in -filter loop being so much slower than piping objects to the Where-Object command.

What I mean by this is you can launch the Show-Command utility with various syntaxes. I’ve put a couple of these below:

Show-Command Test-NetConnection
Show-Command -Name "Test-NetConnection"

Did You Know?

Hey! You! Yes you! Did you know that you can also specify the size of the graphical menu that the Show-Command utility launches?

You can do this by passing the -Height and -Width parameters.

So if you wanted a custom sized window, you could do something like this:

Show-Command -Name "Test-NetConnection" -Height 300 -Width 300

Bad Sides

Once bad side effect to this utility, is that whatever terminal you use to run the Show-Command utility becomes locked until the graphical output is closed. It’s not a big issue, but it doesn’t hang up a PowerShell process, and I wonder what happens if the graphical menu crashes. Does the PowerShell process crash too or does it just stay locked, forever waiting to hear back from the graphical menu?

You also cannot pipe objects to this utility, which is weird because that was my first instinct. Microsoft continues to keep developers on their toes by having different syntaxes for every command!

Profiles

You can also add your custom settings to your PowerShell profile or just to the current PowerShell session. You can do this by specifying the settings you want in the $PSDefaultParameterValues variable. For now, the only settings you can change are the Height, Width and ErrorPopup parameters.

For example, you could do something like this:

$PSDefaultParameterValues = @{
    "Show-Command:Height" = 300
    "Show-Command:Width" = 300
    "Show-Command:ErrorPopup" = $False
}

Running just that in your PowerShell window will set those values for the entire duration of that particular session. If you wanted these settings to load for every PowerShell session, you can add this variable to your PowerShell profile, which is documented here.

Well I hope you enjoyed this post and learnt something new!

I knew as soon as I saw this utility, I just had to share it. I suppose I’m quite late to this one but non the less, I wanted to discuss how I would use the command going forward.

Enjoy! 🎉

Leave a Comment

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

email popup image
Mark Harwood
NEVER miss a blog post again! Subscribe for email notifications whenever a new post is live!
Subscribe
NEVER miss a blog post again! Subscribe for email notifications whenever a new post is live!
Fill Out This Form, And I Will Be In Touch Shortly
Contact form image
I'll Be In Touch Soon