While teaching Powershell courses, I have found that most of the people, in the beginning, have a very hard time interpreting the Powershell help syntax. Which makes sense, all those braces around, optional and required parameters, named and positional, sounds like an Inferno.

The idea crossed my mind to write the Powershell function which can extract all help about specific Cmdlet(real Cmdlet, function, or anything containing command help syntax), in an easy and friendly way.

Check out the source code and then examples


Function Get-CmdletDetail {
    [CmdletBinding(DefaultParameterSetName = 'MandatoryParameter')]
    param (
        # Parameter help description
        [Parameter(Mandatory = $true,
            Position = 0)]
        [Alias('Function')]
        [ValidatePattern('.-.')]
        [string]$Cmdlet,
        # Parameter help description
        [Parameter(ParameterSetName = 'MandatoryParameter')]
        [switch]$MandatoryParameter,
        # Parameter help description
        [Parameter(ParameterSetName = 'ParameterSet')]
        [switch]$ParameterSet,
        # Parameter help description
        [Parameter(ParameterSetName = 'AliasParameter')]
        [switch]$AliasParameter
    )
    begin {
        $ErrorActionPreference = 'Stop'
        try {
            [void]($FindCommand = Get-Command $Cmdlet)
        }
        catch {
            Write-Error "$_" -ErrorAction Stop
        }
    }
    process {
        [hashtable]$CommandParameters = $FindCommand.Parameters
        switch ($PSCmdlet.ParameterSetName) {
            'MandatoryParameter' {
                foreach ($Key in $CommandParameters.Keys) {
                    $FindParameterObject = $CommandParameters.($Key).Attributes | Where-Object { $_ -is [System.Management.Automation.ParameterAttribute] }
                    if (-not [string]::IsNullOrWhiteSpace($FindParameterObject)) {
                        if ($FindParameterObject.Mandatory -eq $true) {
                            $CmdletStructure = $CommandParameters.($Key)
                            [PSCustomObject]@{
                                ParameterName = $CmdletStructure.Name
                                Mandatory     = $true
                                ParameterSet  = $CmdletStructure.ParameterSets.keys -join ', '
                                ParameterType = ($CmdletStructure.ParameterType.Name)
                                Aliases       = ($CmdletStructure.Aliases -join ', ').Trim(' { }')
                            }
                        }
                    }
                }
            }
            'AliasParameter' {
                $AliasCollection = [System.Collections.ArrayList]::new()
                foreach ($Key in $CommandParameters.Keys) {
                    $FindParameterObject = $CommandParameters.($Key).Attributes | Where-Object { $_ -is [System.Management.Automation.AliasAttribute] }
                    if ($FindParameterObject) {
                        $CmdletStructure = $CommandParameters.($Key)
                        $AliasParameterOut = [PSCustomObject]@{
                            AliasName     = ($CmdletStructure.Aliases -join ', ').Trim(' { }')
                            ParameterSet  = $CmdletStructure.ParameterSets.keys -join ', '
                            ParameterType = ($CmdletStructure.ParameterType.Name)
                            ParameterName = $CmdletStructure.Name
                        }
                        [void]$AliasCollection.Add($AliasParameterOut)
                    }
                }
                $AliasCollection | Sort-Object -Property ParameterSet
            }
            'ParameterSet' {
                $ParameterSetCollection = [System.Collections.ArrayList]::new()
                foreach ($Key in $CommandParameters.Keys) {
                    $CmdletStructure = $CommandParameters.($Key)
                    $ParameterSetOut = [PSCustomObject]@{
                        ParameterName = $CmdletStructure.Name
                        ParameterSet  = $CmdletStructure.ParameterSets.keys -join ', '
                        ParameterType = ($CmdletStructure.ParameterType.Name)
                        Aliases       = ($CmdletStructure.Aliases -join ', ').Trim(' { }')
                    }
                    [void]$ParameterSetCollection.Add($ParameterSetOut)
                }
                $ParameterSetCollection | Sort-Object -Property ParameterSet
            }
        }
    }
}

Check out the examples

get-cmdletdetail Get-EventLog -MandatoryParameter
ParameterName                   : LogName
Mandatory                       : True
ParameterSet                    : LogName
ParameterType                   : String
Aliases                         : LN
Position                        : 0
ValueFromPipeline               : False
ValueFromPipelineByPropertyName : False

get-cmdletdetail Get-Process

ParameterName                   : IncludeUserName
Mandatory                       : True
ParameterSet                    : NameWithUserName,IdWithUserName,InputObjectWithUserName
ParameterType                   : SwitchParameter
Aliases                         :
Position                        : False
ValueFromPipeline               : {False, False, False}
ValueFromPipelineByPropertyName : {False, False, False}

ParameterName                   : InputObject
Mandatory                       : True
ParameterSet                    : InputObjectWithUserName,InputObject
ParameterType                   : Process[]
Aliases                         :
Position                        : False
ValueFromPipeline               : {True, True}
ValueFromPipelineByPropertyName : {False, False}

ParameterName                   : Id
Mandatory                       : True
ParameterSet                    : IdWithUserName,Id
ParameterType                   : Int32[]
Aliases                         : PID
Position                        : False
ValueFromPipeline               : {False, False}
ValueFromPipelineByPropertyName : {True, True}

get-cmdletdetail Get-Service -ParameterSet

ParameterName       ParameterSet       ParameterType       Aliases
-------------       ------------       -------------       -------
OutVariable         __AllParameterSets String              ov
InformationAction   __AllParameterSets ActionPreference    infa
ComputerName        __AllParameterSets String[]            Cn
InformationVariable __AllParameterSets String              iv
WarningVariable     __AllParameterSets String              wv
ErrorVariable       __AllParameterSets String              ev
ErrorAction         __AllParameterSets ActionPreference    ea
RequiredServices    __AllParameterSets SwitchParameter     SDO,ServicesDependedOn
OutBuffer           __AllParameterSets Int32               ob
Debug               __AllParameterSets SwitchParameter     db
PipelineVariable    __AllParameterSets String              pv
Verbose             __AllParameterSets SwitchParameter     vb
WarningAction       __AllParameterSets ActionPreference    wa
Exclude             __AllParameterSets String[]
DependentServices   __AllParameterSets SwitchParameter     DS
Include             __AllParameterSets String[]
Name                Default            String[]            ServiceName
DisplayName         DisplayName        String[]
InputObject         InputObject        ServiceController[]

get-cmdletdetail Get-Service -AliasParameter

AliasName              ParameterSet       ParameterType    ParameterName
---------              ------------       -------------    -------------
wv                     __AllParameterSets String           WarningVariable
infa                   __AllParameterSets ActionPreference InformationAction
ov                     __AllParameterSets String           OutVariable
SDO,ServicesDependedOn __AllParameterSets SwitchParameter  RequiredServices
ea                     __AllParameterSets ActionPreference ErrorAction
ev                     __AllParameterSets String           ErrorVariable
ob                     __AllParameterSets Int32            OutBuffer
db                     __AllParameterSets SwitchParameter  Debug
wa                     __AllParameterSets ActionPreference WarningAction
vb                     __AllParameterSets SwitchParameter  Verbose
pv                     __AllParameterSets String           PipelineVariable
Cn                     __AllParameterSets String[]         ComputerName
iv                     __AllParameterSets String           InformationVariable
DS                     __AllParameterSets SwitchParameter  DependentServices
ServiceName            Default            String[]         Name