Last active
July 1, 2016 02:21
-
-
Save adamdriscoll/96e46b8be439d4fd2a12c4f80ac59cd7 to your computer and use it in GitHub Desktop.
Finds aliases set by Set-Alias
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$Ast = { | |
Set-Alias -Name Test -Value SomeValue | |
New-Alias -Name SomeOtherAlias -Value SomeValue | |
}.Ast | |
$SetAliasCommands = $Ast.FindAll({$args[0] -is [System.Management.Automation.Language.CommandAst] -and ($Command.CommandElements[0].Value -eq 'Set-Alias' -or $Command.CommandElements[0].Value -eq 'New-Alias')}, $true) | |
foreach($SetAliasCommand in $SetAliasCommands) | |
{ | |
$NextElementIsNameValue = $false | |
foreach($element in $SetAliasCommand.CommandElements) | |
{ | |
if ($NextElementIsNameValue) | |
{ | |
$element.Value | |
break | |
} | |
if ($element -is [System.Management.Automation.Language.CommandParameterAst] -and $element.ParameterName -eq 'Name') | |
{ | |
$NextElementIsNameValue = $true | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment