
close
close
During my recent summer vacation, I spent some time fishing with my son, who’s an avid fisherman and takes it much more seriously than I do. As we meandered around the lake on the boat, I started thinking that fishing is as much hunting for the right spot or some clue as to where the fish might be. Granted, knowing where to look for these clues takes a lot of experience. And because I’m never truly on vacation, I started thinking about how this might apply to someone learning PowerShell. If you want to know where the fish are, you need to know where to look. Fortunately, PowerShell has a few spots where you can find answers, and I’m happy to share them.
The first place you should stop is the Get-Command cmdlet. Not sure what command to run to get event logs? Take advantage of Get-Command and its support for wildcards. I’m not saying you will get what you need on the first attempt.
You might try this:
advertisment
If you try that, then you'll see a lot of results. Don't give up, let's try again.
Your results might vary depending on what modules you have installed. You can also limit your search by getting commands by noun.Using PowerShell's Get-Command cmdlet. (Image Credit: Jeff Hicks)
You can also use wildcards to search for different nouns. Likewise, you can get commands that use a specific verb.Using nouns with Get-Command. (Image Credit: Jeff Hicks)
If you notice from the screenshots or your own use of Get-Command, you'll see that it finds all types of executables. You can limit the search to a specific type.Limiting our Get-Command search to verbs. (Image Credit: Jeff Hicks)
And perhaps my favorite use of Get-Command is to see what commands are packed away inside a module or snapin.You can also use the same parameters that I showed you earlier to fine tune the results.Using Get-Command with a module. (Image Credit: Jeff Hicks)
You can also use this with snap-ins, even with the –module parameter. Make sure to add the snap-in first.Fine tuning our command. (Image Credit: Jeff Hicks)
Using PowerShell's Get-Command with a snap-in. (Image Credit: Jeff Hicks)
Windows PowerShell's Show-Command
Related to Get-Command is Show-Command. Where the former will tell you where a command comes from, the latter will help you figure out how to use it. You have probably seen this in the PowerShell ISE, which I'll talk about in a moment. Let's say you've looked at help for a cmdlet like Get-VMSnapshot:Let's run Show-Command:Get-VMSnapshot. (Image Credit: Jeff Hicks)
You should get a pop-up like this:Each of the tabs, e.g., VMName, corresponds to a different parameter set. You can click on the different tabs to see the different parameter options. Parameter names with an asterisk are required. I also like the drop-down menus for some parameters. I can go ahead and fill out the form.Get-VMSnapshot pop-up. (Image Credit: Jeff Hicks)
If I click Copy, the final command will be copied to the Windows clipboard. In this case, I will end up with this command:
If I click Run, PowerShell executes the command and closes the dialog box.If you run Show-Command, you'll notice that you won't get your prompt back until the dialog box is dismissed.Executing our newly copied command. (Image Credit: Jeff Hicks)
Using Show-Command in the PowerShell ISE
In the PowerShell ISE, the Show-Command panel is displayed by default. If you've closed it, you can re-open it from the menuHere, the display is a bit different in that you can search for a cmdlet from a given module.The Show Command Add-On in the PowerShell ISE. (Image Credit: Jeff Hicks)
You can also start typing a command name.
In the ISE, you will see this message if the module has not been loaded:Typing a command in the PowerShell ISE. (Image Credit: Jeff Hicks)
Go ahead and click "Show Details" to import the module. In the regular console, PowerShell will automatically import the module. Now I have a form I can fill out.
Here's the tricky part. If I click Run, PowerShell will execute the finished command in the PowerShell ISE. If I click Insert, PowerShell will insert it into the command window.Importing the module in the PowerShell ISE. (Image Credit: Jeff Hicks)
I can also click Copy and then paste it anywhere I want, including the script pane in the ISE. Here's my full command:
Personally, I'd love for an Insert command that lets you place the command into the script pane. It would also be handy if there's an option to use splatting. But regardless, the Show-Command tool makes it easy to discover just what you need. I have a few more PowerShell fishing tips, which I'll save for next time.
More from Jeff Hicks
advertisment
Petri Newsletters
Whether it’s Security or Cloud Computing, we have the know-how for you. Sign up for our newsletters here.
advertisment
More in PowerShell
Microsoft’s New PowerShell Crescendo Tool Facilitates Native Command-Line Wraps
Mar 21, 2022 | Rabia Noureen
Most popular on petri
Log in to save content to your profile.
Article saved!
Access saved content from your profile page. View Saved
Join The Conversation
Create a free account today to participate in forum conversations, comment on posts and more.
Copyright ©2019 BWW Media Group