Latest posts by Adam Bertram (see all)
- How to add leading and ending zeroes to strings in PowerShell - Thu, Dec 7 2017
- How to publish scripts to the PowerShell Gallery - Tue, Dec 5 2017
- Strings in PowerShell: Quotes, formatting, and concatenation - Mon, Dec 4 2017
Since PowerShell is a command-line automation and scripting language, everything typically takes place in text. We run commands, check command output, and write scripts without the mouse. The command line saves time, and scripts can "capture" it to execute again in the future. But sometimes, it's just easier to see something in a clickable GUI.
If you've been using PowerShell for a while, chances are you've probably got lots of modules installed. Modules are the building blocks we use for just about everything, but after a while, your session starts to become full of these building blocks.
It's not uncommon to have dozens of modules installed with thousands of commands available at any given time. Having these many commands available makes it more time-consuming to parse through all of them. Sure, we have cmdlets like Get-Command to search through the commands available. But when you're not sure what you're looking for in the first place, searching with a GUI is sometimes easier.
When basic discovery is necessary, GUIs are typically easier to use. All the elements are available to us in a visual format. Maybe I don't know what commands exist, what the parameters are to those commands, or how they work. When we're going in blind, we have a command built into PowerShell known as Show-Command that can really help out. When we need to discover if a command is available or what kind of parameters it has, we could use Get-Command or Get-Help to figure out these things.
For example, maybe I need to figure out all the Azure cmdlets I have available. I can do this with the Get-Command command using a wildcard.
Get-Command -Name Azure*
Then, when I do find the command I'm looking for, I can use Get-Help -Detailed to discover all the parameters it has. Or I could use (Get-Command -Name COMMANDNAME).Parameters as well. Either way, it's possible. Once we do that work, we'd then craft a sweet one-liner that does everything we need. If you're not a fan of running multiple commands to do this, an alternative is to use the Show-Command cmdlet.
The Show-Command cmdlet allows you to discover commands in modules, see all the parameters they have, and execute that command all in one window. Let's say I want to create a folder and am not sure how to go about it. I can simply run Show-Command, which brings up a graphical window displaying all the commands available even with a search box.
I finally figure out the noun I'm looking for is Item, and as I scroll down, I can see New-Item. Clicking on that immediately presents me with all the available parameters. Text boxes show string and object parameters and checkboxes Switch and Boolean parameters. Not only can I see these parameters, but I also can input values for each and run the command with those parameters right from the same window!
You can also see in the screenshot above that some commands also have tabs. These tabs are parameter sets. The interface uses graphical elements for display like data tables, tabs, text boxes, and checkboxes instead of just text. This allows a user to perform some simple testing or perhaps is great for someone new to the command line. Show-Command doesn't invent anything new. You can obtain the same kind of information via the command line. But Show-Command's biggest asset is being able to search for, display, and execute commands all in a single graphical window.