-
Notifications
You must be signed in to change notification settings - Fork 0
/
Get-ParameterAlias.ps1
71 lines (63 loc) · 1.81 KB
/
Get-ParameterAlias.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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
class ParameterAliasInfo {
[System.Management.Automation.CommandInfo]$Command
[string]$Parameter
[string]$Alias
}
function Get-ParameterAlias {
[CmdletBinding()]
[OutputType([ParameterAliasInfo])]
Param (
[Parameter(Position = 0, ValueFromPipeline)]
[Alias('Function')]
[Alias('Command')]
[String[]]
$Name,
[switch]
$IncludeCommon
)
Begin {
$ParametersToExclude =
if($IncludeCommon) {
Write-Verbose 'Including common parameters'
}
else {
Write-Verbose 'Excluding common parameters'
'WarningVariable',
'ErrorVariable',
'InformationVariable',
'PipelineVariable',
'OutBuffer',
'InformationAction',
'Verbose',
'OutVariable',
'Debug',
'WarningAction',
'ErrorAction',
'WhatIf',
'Confirm'
}
}
Process {
Get-Command -Name $Name -PipelineVariable Command -Type Cmdlet,Function,Filter |
Foreach-Object {
if(-not $Command.Parameters) {
Write-Verbose "$($Command.Name) has no parameters; skipping it."
return
}
Write-Verbose "Processing $($Command.Name)."
@($Command.Parameters.GetEnumerator()).Value |
Where-Object Name -NotIn $ParametersToExclude |
Where-Object Aliases -PipelineVariable Parameter |
ForEach-Object {
$Parameter.Aliases |
ForEach-Object {
[ParameterAliasInfo]@{
Command = $Command
Parameter = $Parameter.Name
Alias = $_
}
}
}
}
}
}