Do You Really Want To Use –EQ?

Steve Lee


Sebastien posted a cool simple script HERE which effectively does a reverse lookup on aliases. Here is the code:
function Get-AliasShortcut([string]$CommandName) {
ls Alias: | ?{ $_.Definition -eq $CommandName }
Set-Alias gas Get-AliasShortcut
Notice that he used –EQ. Whenever you find yourself using –EQ, ask yourself if that is really want you want. You might be cheating yourself out of a ton great stuff. Consider changing the -EQ to -MATCH
That would allow you to do:
PS> Get-AliasShortcut child

CommandType Name Definition
———– —- ———-
Alias gci Get-ChildItem
Alias ls Get-ChildItem
Alias dir Get-ChildItem

PS> Get-AliasShortcut item

CommandType Name Definition
———– —- ———-
Alias cli Clear-Item
Alias clp Clear-ItemProperty
Alias cpi Copy-Item
Alias cpp Copy-ItemProperty
Alias gci Get-ChildItem
Alias gi Get-Item
Alias gp Get-ItemProperty
Alias ii Invoke-Item
Alias mi Move-Item
Alias mp Move-ItemProperty
Alias ni New-Item
Alias ri Remove-Item
Alias rni Rename-Item
Alias rnp Rename-ItemProperty
Alias rp Remove-ItemProperty
Alias si Set-Item
Alias sp Set-ItemProperty
Alias cp Copy-Item
Alias ls Get-ChildItem
Alias mv Move-Item
Alias rm Remove-Item
Alias rmdir Remove-Item
Alias copy Copy-Item
Alias del Remove-Item
Alias dir Get-ChildItem
Alias erase Remove-Item
Alias move Move-Item
Alias rd Remove-Item
Alias ren Rename-Item
Sebastien – thanks for the cool script!
Jeffrey Snover [MSFT]
Windows Management Partner Architect
Visit the Windows PowerShell Team blog at:
Visit the Windows PowerShell ScriptCenter at:

Steve Lee
Steve Lee

Principal Software Engineer Manager, PowerShell

Follow Steve   


    Leave a comment