This may be a stupid question, but are the default aliases (e.g. cd) hardcoded in PowerShell or defined in a hidden “profile” script somewhere?
I don’t have any profiles set (per-user or system-wide) so I’m just wondering where the default ones come from.
They are “built in” but not immutable. Note:
PS > Get-Alias | group Options
Count Name Group
—– —- —–
91 ReadOnly, AllScope {%, ?, ac, asnp…}
46 AllScope {cat, cd, chdir, clear…}
As you can see, there is some partitioning of aliases by the
ReadOnlyoption. TheReadOnlyones are idiomatic in PowerShell, while the mutable ones are for people familiar with other shells. I’ve seen people modifydirto add more functionality, while keepinggcias a straight alias toGet-ChildItem.For broad compatability, I only use the
ReadOnlyaliases in my scripts.Also, because
dirin CMD,lsin UNIX, andgciin PowerShell each work in their own way, I train myself to use the native command, and not an alias.dirtends to work everywhere, butdir -Recursedoes not!As a training exercise, and to test my scripts for compatibility, I sometimes remove the non-
ReadOnlyaliases:There’s a more gentle approach where you replace each alias with a new command that warns you that you’re using one of the compatibility aliases, but lets you keep functioning.
Also, you can change the
ReadOnlyaliases if you really want to, but for the above reasons I’d recommend against it:Directory: C:\Users\Jay
Mode LastWriteTime Length Name
—- ————- —— —-