Beware of Aliases

Can you spot what is wrong here?

PS C:\> function r { "This never runs" }

PS C:\> r
function r { "This never runs" }

PS C:\>

When you run function “r”, it simply returns the function source code.

The reason is that the function name “r” conflicts with a built-in alias:

PS C:\> Get-Alias r

CommandType     Name                                               Version    Source
-----------     ----                                               -------    ------                                        
Alias           r -> Invoke-History                                                                                     

PS C:\>

So always make sure you know your built-in alias names – they always have precedence over functions or any other command. Better yet, adhere to best practice, and always assign Verb-Noun names to your functions.

Twitter This Tip! ReTweet this Tip!