r/PowerShell • u/Mental_Patient_1862 • Jan 15 '21
Aliases suck
Posted this in a reply to a separate thread but posting here to maybe get more folks onboard.
I truly wish folks would stop using aliases when helping people with code. Many (most?) of the questions here (and other forums) are from posters that are new to Powershell. Aliases just add another layer of confusion. As for me, I don't use them because 99% of what I do with PoSh is with scripts and using aliases in scripts makes them much harder to read. So yeah, I have to look them up too.
It's awesome that more experienced coders are willing to share their skill, it just seems to me it'd be awesomer if they would go that tiny extra mile to write out ForEach-Object instead of %, or Where-Object instead of ?, etc.
</whinge>
9
u/dextersgenius Jan 16 '21 edited Jan 16 '21
It's not. OP is mistaken, $_ is the original and $PSItem is the alias.
If you check PowerShell's source code, a comment on line 121 of SpecialVariables.cs says $PSItem is an alias for $_:
https://github.com/PowerShell/PowerShell/blob/master/src/System.Management.Automation/engine/SpecialVariables.cs
In fact, $_ existed since PowerShell v1, and $PSItem was only introduced from v3, as an easier-to-understand alternative to $_. The PowerShell Team clearly state this here:
https://devblogs.microsoft.com/powershell/new-v3-language-features/
Just because someone teaches something for a living doesn't mean they're always correct. :)