Home PowerShell Get-Started Get-Started: PowerShell 3.0 – Mastering parameters with the Show-Command CmdLet

Welcome to the first PowerShell 3.0 post in the Get-Started learning series. Today we are going to work with PowerShell 3.0 and the Show-Command CmdLet. Because this is a PowerShell 3.0 CmdLet I am assuming that you are working with Windows 8, Windows Server 2012 or that you have installed the PowerShell CTP for your existing environment.

The Show-Command CmdLet is new with PowerShell 3.0 and what it brings us is a really great way to explore and extend our understanding of parameters.

For our example we will use the Out-FileCmdLet as our target. In your PowerShell console you simply type Show-Command <CmdLet name here>

Show-Command Out-File

This will bring up a GUI window that presents all of the parameters you can edit for this particular CmdLet. It is context sensitive so the parameters will change depending on which CmdLet you launch.

This is what we see with our Out-File CmdLet:

We can see that for Out-File we can use the following parameters:

  • Append
  • Confirm
  • Encoding
  • Force
  • InputObject
  • NoClobber
  • WhatIf
  • Width

You would find these same parameters listed if you were to use the Get-Help Out-File command also, but for many people it can be confusing to understand the help format and it is especially helpful for those who are used to working with the GUI.

One extra feature we have is that not only are the CmdLet specific parameters shown, but there are also Common Parameters available. These include:

  • Debug
  • ErrorAction
  • ErrorVariable
  • OutBuffer
  • OutVariable
  • Verbose
  • WarningAction
  • WarningVariable

Common Parameters are those which apply to all CmdLets so these will be more familiar once you get used to using them. You may not need to use them, but it is good to explore them as your skill level increases. They will add great features to your scripts when you begin to work with error handling.

In this case I will only add a couple of parameters which are -Append, -NoClobber and my file path which is c:\temp\MyOutputFile.txt.

Once we populate our parameters we can click on the Run button to launch the full command. But before we do that, you may also notice that there is a Copy button. It is exactly what you think it is, which is a way to copy the full command to the clipboard for pasting elsewhere.

Once we click the Copy button we can now paste the output into your editor of choice to use for a script file. I’m a big fan of Notepad myself so this is where I will paste my result to see what the full command looks like.

What I recommend is that you use the Show-Command CmdLet to explore what parameters can be used for your various CmdLets and then eventually you will build your comfort and understanding of the capabilities and options of each one for more advanced scripting.

One note about the Show-Command is that because it is a GUI, you can only use it on the console and not in a remote PowerShell session (PSSession).

I recommend that you go through as many CmdLets with the Show-Command CmdLet now and get more and more experience with how to get the most of each and every CmdLet you use.

Happy scripting!

SIMILAR ARTICLES

2 COMMENTS

Leave a Reply