Tag Archives: Verb

Get-Command

NAME
    Get-Command

SYNOPSIS
    Gets basic information about cmdlets and other elements of Windows PowerShell commands.

SYNTAX
    Get-Command [[-Name] <string[]>] [-CommandType {Alias | Function | Filter | Cmdlet | ExternalScript | Application | Script | All}] [[-ArgumentList] <Object[]>] [-Module <string[]>] [-Syntax] [-TotalCount <int>] [<CommonParameters>]

    Get-Command [-Noun <string[]>] [-Verb <string[]>] [[-ArgumentList] <Object[]>] [-Module <string[]>] [-Syntax] [-TotalCount <int>] [<CommonParameters>]

DESCRIPTION
    The Get-Command cmdlet gets basic information about cmdlets and other elements of Windows PowerShell commands in the session, such as Aliases, Functions, filters, scripts, and applications.

    Get-Command gets its data directly from the code of a cmdlet, Function, script, or Alias, unlike Get-Help, which gets its information from help topic files.

    Without parameters, “Get-Command” gets all of the cmdlets and Functions in the current session. “Get-Command *” gets all Windows PowerShell elements and all of the non-Windows-PowerShell files in the Path Environment Variable ($env:path). It groups the files in the “Application” command type.

    You can use the Module parameter of Get-Command to find the commands that were added to the session by adding a Windows PowerShell snap-in or importing a module.

PARAMETERS
    -ArgumentList <Object[]>
        Gets information about a cmdlet or Function when it is used with the specified parameters (“arguments”), such as a path. The Alias for ArgumentList is Args.

        To detect parameters that are added to a cmdlet when it is used with a particular provider, set the value of ArgumentList to a path in the provider drive, such as “HKML\Software” or “cert:\my”.

        Required?                    false
        Position?                    2
        Default value
        Accept pipeline input?     false
        Accept wildcard characters? false

    -CommandType <CommandTypes>
        Gets only the specified types of commands. Use “CommandType” or its Alias, “Type”. By default, Get-Command gets cmdlets and Functions.

        Valid values are:
        — Alias: All Windows PowerShell Aliases in the current session.

        — All: All command types. It is the equivalent of “Get-Command *”.

        — Application: All non-Windows-PowerShell files in paths listed in the Path Environment Variable ($env:path), including .txt, .exe, and .dll files.

        — Cmdlet: The cmdlets in the current session. “Cmdlet” is the default.

        — ExternalScript: All .ps1 files in the paths listed in the Path Environment Variable ($env:path).

        — Filter and Function: All Windows PowerShell Functions.

        — Script: Script blocks in the current session.

        Required?                    false
        Position?                    named
        Default value
        Accept pipeline input?     true (ByPropertyName)
        Accept wildcard characters? false

    -Module <string[]>
        Gets the commands that came from the specified modules or snap-ins. Enter the names of modules or snap-ins, or enter snap-in or module objects.

        You can refer to this parameter by its name, Module, or by its Alias, PSSnapin. The parameter name that you choose has no effect on the command or its output.

        This parameter takes string values, but you can also supply a PSModuleInfo or PSSnapinInfo object, such as the objects that Get-Module, Get-PSSnapin, and Import-PSSession return.

        Required?                    false
        Position?                    named
        Default value                None
        Accept pipeline input?     true (ByPropertyName)
        Accept wildcard characters? false

    -Name <string[]>
        Gets information only about the cmdlets or command elements with the specified name. <String> represents all or part of the name of the cmdlet or command element. Wildcards are permitted.

        To list commands with the same name in execution order, type the command name without wildcard characters. For more information, see the Notes section.

        Required?                    false
        Position?                    1
        Default value
        Accept pipeline input?     true (ByValue, ByPropertyName)
        Accept wildcard characters? false

    -Noun <string[]>
        Gets cmdlets and Functions with names that include the specified noun. <String> represents one or more nouns or noun patterns, such as “process” or “*item*”. Wildcards are permitted.

        Required?                    false
        Position?                    named
        Default value
        Accept pipeline input?     true (ByPropertyName)
        Accept wildcard characters? false

    -Syntax [<SwitchParameter>]
        Gets only specified data about the command element.
                 * For Aliases, retrieves the standard name.
                 * For cmdlets, retrieves the syntax.
                 * For Functions and filters, retrieves the Function definition.
                 * For scripts and applications (files), retrieves the path and filename.

        Required?                    false
        Position?                    named
        Default value
        Accept pipeline input?     true (ByPropertyName)
        Accept wildcard characters? false

    -TotalCount <int>
        Gets only the specified number of command elements. You can use this parameter to limit the output of a command.

        Required?                    false
        Position?                    named
        Default value
        Accept pipeline input?     true (ByPropertyName)
        Accept wildcard characters? false

    -Verb <string[]>
        Gets information about cmdlets and Functions with names that include the specified verb. <String> represents one or more verbs or verb patterns, such as “remove” or *et”. Wildcards are permitted.

        Required?                    false
        Position?                    named
        Default value
        Accept pipeline input?     true (ByPropertyName)
        Accept wildcard characters? false

    <CommonParameters>
        This cmdlet supports the common parameters: Verbose, Debug,
        ErrorAction, ErrorVariable, WarningAction, WarningVariable,
        OutBuffer and OutVariable. For more information, type,
        “Get-Help about_CommonParameters“.

INPUTS
    System.String
        You can pipe a “Name”, “Command”, and “Verb” noun-property specified, or a string object to Get-Command.

OUTPUTS
    Object
        The type of object returned depends on the type of command element retrieved. For example, Get-Command on a cmdlet retrieves a CmdletInfo object, while Get-Command on a DLL retrieves an ApplicationInfo object.

NOTES

        Without parameters, “Get-Command” gets information about the Windows PowerShell cmdlets and Functions. Use the parameters to qualify the elements retrieved.

        Unlike Get-Help, which displays the contents of XML-based help topic files, Get-Command gets its cmdlet information directly from the cmdlet code in the system.

        Get-Command returns the commands in alphabetical order. When the session contains more than one command with the same name, Get-Command returns the commands in execution order. The first command that is listed is the command that runs when you type the command name without qualification. For more information, see about_command_precedence.

    ————————– EXAMPLE 1 ————————–

    C:\PS>Get-Command

    Description
    ———–
    This command gets information about all of the Windows PowerShell cmdlets and Functions.

    The default display lists the command type (“Cmdlet” or “Function” or “Filter”), the name of the cmdlet or Function, and the syntax or Function definition.

    ————————– EXAMPLE 2 ————————–

    C:\PS>Get-Command -Verb set | Format-List

    Description
    ———–
    This command gets information about all of the cmdlets and Functions with the verb “set”, and it displays some of that information in a list.

    The list format includes fields that are omitted from the table display, including the complete syntax. To display all fields (all properties of the object), type “Get-Command -Verb set | Format-List *”.

    ————————– EXAMPLE 3 ————————–

    C:\PS>Get-Command -type cmdlet | Sort-Object noun | Format-Table -group noun

    Description
    ———–
    This command retrieves all of the cmdlets, sorts them alphabetically by the noun in the cmdlet name, and then displays them in noun-based
    groups. This display can help you find the cmdlets for a task.

    By default, Get-Command displays items in the order in which the system discovers them, which is also the order in which they are selected to run when a run command is ambiguous.

    ————————– EXAMPLE 4 ————————–

    C:\PS>Get-Command -Module Microsoft.PowerShell.Security, TestModule

    Description
    ———–
    This command gets the commands in the Microsoft.PowerShell.Security snap-in and the Test-Module module.

    The Module parameter gets commands that were added by importing modules or adding Windows PowerShell snap-ins.

    ————————– EXAMPLE 5 ————————–

    C:\PS>Get-Command Get-ChildItem -args cert: -Syntax

    Description
    ———–
    This command retrieves information about the Get-ChildItem cmdlet when Get-ChildItem is used with the Windows PowerShell Certificate provider.

    When you compare the syntax displayed in the output with the syntax that is displayed when you omit the Args (ArgumentList) parameter, you’ll see that the Certificate provider dynamically adds a parameter, CodeSigningCert, to the Get-ChildItem cmdlet.

    ————————– EXAMPLE 6 ————————–

    C:\PS>(Get-Command Get-ChildItem -ArgumentList cert:).parametersets[0].parameters | Where-Object { $_.IsDynamic }

    Description
    ———–
    This command retrieves only parameters that are added to the Get-ChildItem cmdlet dynamically when it is used with the Windows PowerShell Certificate provider. This is an alternative to the method used in the previous example.

    In this command, the “Get-Command Get-ChildItem -ArgumentList cert:” is processed first. It requests information from Get-Command about the Get-ChildItem cmdlet when it is used with the Certificate provider. The “.parametersets[0]” selects the first parameter set (set 0) of “Get-ChildItem -ArgumentList cert:” and “.parameters” selects the parameters in that parameter set. The resulting parameters are piped to the Where-Object cmdlet to test each parameter (“$_.”) by using the IsDynamic property. To find the properties of the objects in a command, use Get-Member.

    ————————– EXAMPLE 7 ————————–

    C:\PS>Get-Command *

    Description
    ———–
    This command gets information about the Windows PowerShell cmdlets, Functions, filters, scripts, and Aliases in the current console.

    It also gets information about all of the files in the paths of the Path Environment Variable ($env:path). It returns an ApplicationInfo object (System.Management.Automation.ApplicationInfo) for each file, not a FileInfo object (System.IO.FileInfo).

    ————————– EXAMPLE 8 ————————–

    C:\PS>Get-Command | Where-Object {$_.definition -like “*first*”}

    CommandType     Name                        Definition
    ———–     —-                        ———
    Cmdlet         Select-Object             Select-Object [[-Property]

    Description
    ———–
    This command finds a cmdlet or Function based on the name of one of its parameters. You can use this command to identify a cmdlet or Function when all that you can recall is the name of one of its parameters.

    In this case, you recall that one of the cmdlets or Functions has a First parameter that gets the first “n” objects in a list, but you cannot remember which cmdlet it is.

    This command uses the Get-Command cmdlet to get a CmdletInfo object representing each of the cmdlets and Functions in the session. The CmdletInfo object has a Definition property that contains the syntax of the cmdlet or Function, which includes its parameters.

    The command uses a pipeline operator (|) to pass the CmdletInfo object to the Where-Object cmdlet, which examines the definition (syntax) of each object ($_) for a value that includes “first”.

    The result shows that the First parameter belongs to the Select-Object cmdlet.

    ————————– EXAMPLE 9 ————————–

    C:\PS>Get-Command dir | Format-List

    Name             : dir
    CommandType     : Alias
    Definition        : Get-ChildItem
    ReferencedCommand : Get-ChildItem
    ResolvedCommand : Get-ChildItem

    Description
    ———–
    This example shows how to use the Get-Command cmdlet with an Alias. Although it is typically used on cmdlets, Get-Command also displays information about the code in scripts, Functions, Aliases, and executable files.

    This command displays the “dir” Alias in the current console. The command pipes the result to the Format-List cmdlets.

    ————————– EXAMPLE 10 ————————–

    C:\PS>Get-Command notepad

    CommandType     Name         Definition
    ———–     —-         ———-
    Application     notepad.exe    C:\WINDOWS\system32\notepad.exe
    Application     NOTEPAD.EXE    C:\WINDOWS\NOTEPAD.EXE

    Description
    ———–
    This example shows how to use Get-Command to determine which command Windows PowerShell runs when it has access to multiple commands with the same name. When you use the Name parameter without wildcard characters, Get-Command lists the commands with that name in execution precedence order.

    This command shows which Notepad program Windows PowerShell runs when you type “Notepad” without a fully qualified path. The command uses the Name parameter without wildcard characters.

    The sample output shows the Notepad commands in the current console. It indicates that Windows PowerShell will run the instance of Notepad.exe in the C:\Windows\System32 directory.

    ————————– EXAMPLE 11 ————————–

    C:\PS>(Get-Command Get-Date).pssnapin

    C:\PS> (Get-Command remove-gpo).module

    Description
    ———–
    These commands show how to find the snap-in or module from which a particular cmdlet originated.

    The first command uses the PSSnapin property of the CmdletInfo object to find the snap-in that added the Get-Date cmdlet.

    The second command uses the Module property of the CmdletInfo object to find the module that added the Remove-GPO cmdlet.

RELATED LINKS
    Online version: http://go.microsoft.com/fwlink/?LinkID=113309
    about_command_precedence
    Get-Help
    Get-PSDrive
    Get-Member
    Import-PSSession
    Export-PSSession