Skip to content

Commit 0a858af

Browse files
committed
✨ Enhance parameter detail output
also update unicode data
1 parent 90030ed commit 0a858af

File tree

3 files changed

+974
-18
lines changed

3 files changed

+974
-18
lines changed

Get-CommandParameters.ps1

Lines changed: 48 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,17 @@ Get-Command
1414
.EXAMPLE
1515
Get-CommandParameters.ps1 Write-Verbose
1616
17-
Name : Message
18-
ParameterType : System.String
19-
ParameterSets : {[__AllParameterSets, System.Management.Automation.ParameterSetMetadata]}
20-
IsDynamic : False
21-
Aliases : {Msg}
22-
Attributes : {, System.Management.Automation.AllowEmptyStringAttribute, System.Management.Automation.AliasAttribute}
23-
SwitchParameter : False
17+
CommandName : Write-Verbose
18+
ParameterName : Message
19+
ParameterType : System.String
20+
TypeAlias : string
21+
ParameterSets : {__AllParameterSets}
22+
Mandatory : True
23+
Position : 0
24+
ValueFromPipelineByPropertyName : False
25+
ValueFromPipeline : True
26+
SwitchParameter : False
27+
IsDynamic : False
2428
2529
.EXAMPLE
2630
Get-CommandParameters.ps1 Out-Default -NamesOnly
@@ -34,7 +38,7 @@ InputObject
3438
[OutputType([string])]
3539
Param(
3640
# The name of a cmdlet.
37-
[Parameter(Position=0,Mandatory=$true)][string] $CommandName,
41+
[Parameter(Position=0,Mandatory=$true,ValueFromPipelineByPropertyName=$true)][Alias('Name')][string] $CommandName,
3842
# The name of a parameter set defined by the cmdlet.
3943
[string] $ParameterSet,
4044
# Return only the parameter names (otherwise)
@@ -51,6 +55,40 @@ Begin
5155
[string[]][System.Management.Automation.PSCmdlet]::CommonParameters +
5256
[string[]][System.Management.Automation.PSCmdlet]::OptionalCommonParameters
5357
}
58+
$typeAlias = @{}
59+
Get-TypeAccelerators.ps1 |
60+
Where-Object Alias -NotMatch '\d\d\z' |
61+
ForEach-Object {$typeAlias[$_.Type.FullName] = $_.Alias}
62+
63+
filter ConvertFrom-ParameterMetadata
64+
{
65+
[CmdletBinding()] Param(
66+
[Parameter(Position=0,Mandatory=$true)][string] $CommandName,
67+
[Parameter(ValueFromPipelineByPropertyName=$true,Mandatory=$true)][string] $Name,
68+
[Parameter(ValueFromPipelineByPropertyName=$true,Mandatory=$true)][type] $ParameterType,
69+
[Parameter(ValueFromPipelineByPropertyName=$true,Mandatory=$true)]
70+
[Collections.Generic.Dictionary[string,Management.Automation.ParameterSetMetadata]] $ParameterSets,
71+
[Parameter(ValueFromPipelineByPropertyName=$true,Mandatory=$true)][bool] $IsDynamic,
72+
[Parameter(ValueFromPipelineByPropertyName=$true)][string[]] $Aliases,
73+
[Parameter(ValueFromPipelineByPropertyName=$true,Mandatory=$true)][attribute[]] $Attributes,
74+
[Parameter(ValueFromPipelineByPropertyName=$true,Mandatory=$true)][bool] $SwitchParameter
75+
)
76+
$paramAtts = $Attributes |Where-Object {$_ -is [Management.Automation.ParameterAttribute]}
77+
return [pscustomobject]@{
78+
CommandName = $CommandName
79+
ParameterName = $Name
80+
ParameterType = $ParameterType
81+
TypeAlias = $ParameterType.FullName -replace '(\A\w+(?:\.\w+)*)(\W+)?',
82+
{$typeAlias.ContainsKey($_.Groups[1].Value) ? ($typeAlias[$_.Groups[1].Value]+$_.Groups[2].Value) : $_.Value}
83+
ParameterSets = $ParameterSets.Keys
84+
Mandatory = $paramAtts.Mandatory
85+
Position = $paramAtts.Position
86+
ValueFromPipelineByPropertyName = $paramAtts.ValueFromPipelineByPropertyName
87+
ValueFromPipeline = $paramAtts.ValueFromPipeline
88+
SwitchParameter = $SwitchParameter
89+
IsDynamic = $IsDynamic
90+
}
91+
}
5492
}
5593
Process
5694
{
@@ -63,7 +101,7 @@ Process
63101
Select-Object -ExpandProperty Parameters |
64102
Where-Object Name -notin $excludeParams
65103
if($NamesOnly) {return $params |Select-Object -ExpandProperty Name}
66-
else {return $params}
104+
else {return $params |ConvertFrom-ParameterMetadata $CommandName}
67105
}
68106
else
69107
{
@@ -72,7 +110,7 @@ Process
72110
{
73111
return $cmd.Parameters.Keys |
74112
Where-Object {$_ -notin $excludeParams} |
75-
ForEach-Object {$cmd.Parameters[$_]}
113+
ForEach-Object {$cmd.Parameters[$_] |ConvertFrom-ParameterMetadata $CommandName}
76114
}
77115
}
78116
}

0 commit comments

Comments
 (0)