Private/Get-ParameterName.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
Function Get-ParameterName {
#Get parameter names for a specific command
    [cmdletbinding()]
    param(
        [string]$command,
        [string]$parameterset = $null,
        [string[]]$excludeDefault = $( "Verbose",
                                "Debug",
                                "ErrorAction",
                                "WarningAction",
                                "ErrorVariable",
                                "WarningVariable",
                                "OutVariable",
                                "OutBuffer",
                                "PipelineVariable",
                                "Confirm",
                                "Whatif" ),
        [string[]]$exclude = $( "Passthru", "Commit" )
    )
    if($parameterset)
    {
        ((Get-Command -name $command).ParameterSets | Where-Object {$_.name -eq $parameterset} ).Parameters.Name | Where-Object {($exclude + $excludeDefault) -notcontains $_}
    }

    else
    {
        ((Get-Command -name $command).ParameterSets | Where-Object {$_.name -eq "__AllParameterSets"} ).Parameters.Name | Where-Object {($exclude + $excludeDefault) -notcontains $_}
    }
}