0

Why Its A Bad Idea To Use Shortcode Or Alias’ In Scripts

Seriously.. So I’m trying to teach a co-worker some Powershell techniques and skills to help him automate some of his work and he comes across | ? {bla bah}. Before he asks me what this exactly means he goes on a wild Google goose chase trying to find out what ? means in Powershell. This can obviously be very frustrating if you’re barely getting to know the basics. A good rule of thumb is to use shortcode or the alias in the command line, and use the full cmdlet in your scripts.

Just remember when creating your scripts, there is a pretty good possibility that it will remain in use many years after you leave. Some people who are just starting their Powershell journey might not have the knowledge to understand whats going on, let alone when you use shortcode / aliases in there.

Just thought I would throw that out there..

Edit: There is the method of doing a Get-Alias ? and it will provide you the output of what that means, however, most people won’t know that’s even a thing.

Get-Alias use Shortcode
 

Just for reference:
% in Powershell means ForEach-Object.
? in Powershell means Where-Object.

If you’re looking to expand your Powershell knowledge check out Don Jones Learn Powershell In a Month Of Lunches Book.
 

Also, as a reminder, don’t forget to check out our Youtube Channel for awesome Sysadmin tutorials and How-To’s.

4.3/5 - (6 votes)

Paul Contreras

Hi, my name is Paul and I am a Sysadmin who enjoys working on various technologies from Microsoft, VMWare, Cisco and many others. Join me as I document my trials and tribulations of the daily grind of System Administration.

Leave a Reply

Your email address will not be published. Required fields are marked *