Question Need simplification on Get-command cmdlet

can anybody please give an explanation for this command?, I am not getting it after “get-command get-service | select -ExpandProperty parameters” as this is giving a “System.Collections.Generic.Dictionary” object and didn’t see any property with the name “Computername”.

(get-command get-service | select -ExpandProperty parameters).computername.aliases

When you need help or explanation that is what the built-in PoSH help files are for.

    # Get parameters, examples, full and Online help for a cmdlet or function

    (Get-Command -Name Get-Service).Parameters
    Get-help -Name Get-Service -Examples
    Get-help -Name Get-Service -Full
    Get-help -Name Get-Service -Online

When you are trying to come to grips with a piece of code. Never approach the whole thing at once. Break in to its pieces and run one at a time, then put it back together.

This …

"System.Collections.Generic.Dictionary

… means there is more than one thing being returned and you have to break out what you want.

    # Get basic cmdlet/function info 
    Get-Command Get-Service | Format-Table -AutoSize

    CommandType Name        Version Source                         
    ----------- ----        ------- ------                         
    Cmdlet      Get-Service 3.1.0.0 Microsoft.PowerShell.Management


    # Show all the parameters of this cmdlet/function
    Get-Command Get-Service | select-Object -ExpandProperty parameters

    Key                 Value                                         
    ---                 -----                                         
    Name                System.Management.Automation.ParameterMetadata
    ComputerName        System.Management.Automation.ParameterMetadata
    DependentServices   System.Management.Automation.ParameterMetadata
    RequiredServices    System.Management.Automation.ParameterMetadata
    DisplayName         System.Management.Automation.ParameterMetadata
    Include             System.Management.Automation.ParameterMetadata
    Exclude             System.Management.Automation.ParameterMetadata
    InputObject         System.Management.Automation.ParameterMetadata
    Verbose             System.Management.Automation.ParameterMetadata
    Debug               System.Management.Automation.ParameterMetadata
    ErrorAction         System.Management.Automation.ParameterMetadata
    WarningAction       System.Management.Automation.ParameterMetadata
    InformationAction   System.Management.Automation.ParameterMetadata
    ErrorVariable       System.Management.Automation.ParameterMetadata
    WarningVariable     System.Management.Automation.ParameterMetadata
    InformationVariable System.Management.Automation.ParameterMetadata
    OutVariable         System.Management.Automation.ParameterMetadata
    OutBuffer           System.Management.Automation.ParameterMetadata
    PipelineVariable    System.Management.Automation.ParameterMetadata


    # Get details on the ComputerName key / property
    (get-command get-service | select -ExpandProperty parameters).computername

    Name            : ComputerName
    ParameterType   : System.String[]
    ParameterSets   : {[__AllParameterSets, System.Management.Automation.ParameterSetMetadata]}
    IsDynamic       : False
    Aliases         : {Cn}
    Attributes      : {__AllParameterSets, System.Management.Automation.ValidateNotNullOrEmptyAttribute, System.Management.Automation.AliasAttribute}
    SwitchParameter : False

    # Get the shortname for the ComputerName key / property.
    (get-command get-service | select -ExpandProperty parameters).computername.aliases

    Cn

You could have just done this as well, to get the same result.

    (Get-Command Get-Service).Parameters

    (Get-Command Get-Service).Parameters.Values

    (Get-Command Get-Service).Parameters.ComputerName

    Name            : ComputerName
    ParameterType   : System.String[]
    ParameterSets   : {[__AllParameterSets, System.Management.Automation.ParameterSetMetadata]}
    IsDynamic       : False
    Aliases         : {Cn}
    Attributes      : {__AllParameterSets, System.Management.Automation.ValidateNotNullOrEmptyAttribute, System.Management.Automation.AliasAttribute}
    SwitchParameter : False

    (Get-Command Get-Service).Parameters.ComputerName.Aliases

Hey Buddy,

Thank you for the detailed explanation.

Regards,
Abhi