This is the first in what I hope will be an occasional series of tips for PowerShell users: short posts which don’t intend to give guidance, but merely a tip on a feature you may not be aware of, or maybe even answers to some of the recurring questions that come up in #PowerShell. We’ll see how this goes …
This means that using an Alias, you can override anything (and since you can’t have multiple aliases with the same name, that makes aliases the ultimate way to disambiguate commands).
Functions and filters (there’s really no such thing as a filter) come before cmdlets (yes, even built-in cmdlets) and scripts (that is, your .ps1 files which are in your path, and are called “ExternalScripts” by PowerShell) come before applications, which come before scripts written in other languages, like .vbs or .bat or .cmd (even though they’re all shown as “Application” type commands, PowerShell prioritizes apps over executable scripts which are associated with an engine).
Incidentally, I’m not actually sure what a “Script” is (it’s a CommandType for Get-Command, but there aren’t any on my PCs) if anyone can run get-command -type "Script" and get something output, please let me know what it was.
It’s important to understand that this precedence order is not what you get if you run Get-Command (Get-Command merely orders everything alphabetically by name). In fact, as far as I know, PowerShell doesn’t give you a way to get a list of commands in the order that they would execute, nor does it specify any way of determining that order in the documentation. If you would like to see the proper order, you could use the following “filter” function, and sort by Order bearing in mind that it really only works precisely when you type the full command without wildcards.
Oh, by the way, in case it’s not obvious … “luimcxp” is the second letter of each “CommandType” (which is unique in each one) in the order that I think they belong in … so IndexOf( $($_.CommandType)[1] ) gives us the correct ordering for the command in $_.
Powershell beginner here. Off topic, this page helped me stumble on this:
filter kb { $_ / 1024}
filter mb { $_ / 1024 / 1024 }
filter tb { $_ / 1024 / 1024 / 1024 }
I use Powershell as a calculator:
10mb + 285kb | mb
Goodbye calc!
Well that’s embarrassing. Meant “gb” not “tb”