Aliases Can Be Dangerous

by Jul 23, 2014

All PowerShell versions

Aliases enjoy the highest priority among executable commands in PowerShell, so if you have ambiguous commands, PowerShell always picks the alias.

This can be dangerous: if you allow others to change your PowerShell environment, and possibly add aliases you do not know about, your scripts behave completely different.

Here is a simple call that adds the alias Get-ChildItem and lets it point to ping.exe:

Set-Alias -Name Get-ChildItem -Value ping

This will change everything: Not only will Get-ChildItem now ping instead of list folder content. Also, all aliases (like “dir” and “ls”) now ping. Just imagine the alias would point to format.exe instead, and think what your scripts would now do.

Twitter This Tip! ReTweet this Tip!