Show-Command

Create Windows PowerShell commands in a graphical command window.

Syntax
      Show-Command [[-Name] String] [-ErrorPopup] [-Height Double]
         [-NoCommonParameter] [-PassThru] [-Width Double] [CommonParameters]

Key
   -ErrorPopup
        Display errors in a pop-up window, in addition to displaying them at the command  line.
        By default, when a command that is run in a Show-Command window generates an error, the error is 
        displayed only at the command line.
        
        Also, when you run the command (by using the Run button in the Show-Command window), the ErrorPopup parameter 
        returns the command results to the current command, instead of running the command and returning its output to 
        a new command. You can use this feature to save the command results in a variable.
        
    -Height Double
        The height of the Show-Command window in pixels. Enter a value between 300 and the number of pixels 
        in the screen resolution. If the value is too large to display the command window on the screen, Show-Command 
        generates an error. The default height is 600 pixels. For a Show-Command command that includes the -Name 
        parameter, the default height is 300 pixels.
        
    -Name String
        Display a command window for the specified command. Enter the name of one command, such as the name of a 
        cmdlet, function, workflow, or CIM command. If you omit this parameter, Show-Command displays a command window 
        that lists all of the PowerShell commands in all modules installed on the computer.
        
    -NoCommonParameter
        Omit the 'Common Parameters' section of the command display. By default, the Common  Parameters
        appear in an expandable section at the bottom of the command window.
        
    -PassThru
        Return an object representing the item with which you are working.
        By default, this cmdlet does not generate any output.
        
        To run the command string, copy and paste it at the command prompt or save it in a variable and use the 
        Invoke-Expression cmdlet to run the string in the variable.
        
    -Width Double
        The width of the Show-Command window in pixels. Enter a value between 300 and the number of pixels 
        in the screen resolution. If the value is too large to display the command window on the screen, Show-Command 
        generates an error. The default width is 300 pixels.

Show-Command lets you create a PowerShell command in a command window. You can use the features of the command window to run the command or have it return the command to you.

Show-Command is a useful teaching and learning tool and works on all command types, including cmdlets, functions, workflows and CIM commands.

Without parameters, Show-Command displays a command window that lists all available commands in all installed modules. To find the commands in a module, select the module from the Modules drop-down list. To select a command, click the command name. To use the command window, select a command, either by using the Name or by clicking the command name in the Commands list.

Each parameter set is displayed on a separate tab. Asterisks indicate the mandatory parameters. To enter values for a parameter, type the value in the text box or select the value from the drop-down box. To add a switch parameter, click to select the parameter check box. When you're ready, you can click Copy to copy the command that you've created to the clipboard or click Run to run the command.

You can also use the -PassThru parameter to return the command to the host program, such as the Windows PowerShell console. To cancel the command selection and return to the view that displays all commands, press Ctrl and click the selected command.

In the Windows PowerShell Integrated Scripting Environment (ISE), a variation of the Show-Command window is displayed by default. For information about using this command window, see the Windows PowerShell ISE Help topics.

This cmdlet was introduced in Windows PowerShell 3.0.

Standard Aliases for Show-Command: shcm

Examples

Open the Commands window:

PS C:\> Show-Command

Open a cmdlet in the Commands window:

PS C:\> Show-Command -Name "Invoke-Command"

Display a cmdlet in the Commands window and return (passthru) a string:

PS C:\> Show-Command -PassThru Get-EventLog -LogName "Windows PowerShell" -Newest 5

Specify new default parameter values:

PS C:\> $PSDefaultParameterValues = @{"Show-Command:Height" = 700; "Show-Command:Width" = 1000; "Show-Command:ErrorPopup" = $True}

A Preference Variable value that you set in this way will be specific to the current PowerShell session. To make it effective in all PowerShell sessions, add it to your PowerShell profile.

Send output to a grid view:

PS C:\> Show-Command Get-ChildItem | Out-GridView

Save a command to a variable and then execute it:

PS C:\> $C = Show-Command -PassThru Get-EventLog -LogName "Windows PowerShell" -Newest 5
PS C:\> Invoke-Expression $C

Use the ErrorPopup parameter to returns command output and also display any errors:

PS C:\> $P = Show-Command Get-Process -ErrorPopup
PS C:\> $P

When you run this command, the Show-Command window opens. You can use the window features to set parameter values. To run the command, click the Run button in the Show-Command window.

"Some commands are more easily given than obeyed" ~ George R. R. Martin, A Game of Thrones, Jon (VII)

Related PowerShell Cmdlets:

Get-Help - Open the help file.
Get-Command - Retrieve basic information about a command.


 
Copyright © 1999-2020 SS64.com
Some rights reserved