Star InactiveStar InactiveStar InactiveStar InactiveStar Inactive
 

Windows PowerShell aliases are very handy. They typically have fewer characters than the commands and parameters that they represent, so they’re quicker to type and great for tweeting. However, it has long been an established best practice that aliases should not be used in blogs, in help, in examples, or in any shared scripts and commands. They create an extra layer of confusion for beginners and they’re an obstacle for anyone who needs to maintain the script.

Still, we use them. I know that, despite my best efforts, I type “dir” and “where” and “gcm” and “ipmo” and “sls”  and, worst of all, “foreach” when I mean the ForEach-Object cmdlet, not the ForEach statement.

Fortunately, some nifty features in PowerShell Studio make it easy to conform to the best practice, despite our habits.

  • When you type an alias, PrimalSense shows that it’s a alias.

PrimalSense recognizes aliases

  • When you type a cmdlet alias or parameter alias and then press TAB, PowerShell Studio expands it. (You can disable this feature in Options\Editor\Enable alias tab expansion.)
  • When you type a partial parameter name (such as –m or –mod for –Module) and a space, PowerShell Studio expands it.
  • To expand an alias, right-click and click Expand to Cmdlet or Expand Parameter.

 

But, when I’m scripting, I’m a bit too focused to think about aliases. Instead, when I’m done with my script, just before I sign it, I type:

CTRL + SHIFT + A

Ctrl+Shift+A converts all cmdlet and parameter aliases, and parameter partial names*, to their full names with correct capitalization. What an easy way to support a best practice.

Oh, and in case you’re wondering, PowerShell Studio is happy to undo all of your good deeds. You can right-click and click Convert to Alias or type Ctrl+Shift+Alt+A to convert all cmdlet and parameter names to aliases.

 

* A few notes:

  • Beginning in PowerShell Studio 2014 version 4.1.72, Ctrl+Shift+A expands aliases and Ctrl+Shift+Alt+A contracts names to their aliases. In earlier versions, Ctrl+Shift+Alt+A expands aliases and Ctrl+Shift+A contracts them.
  • Also, beginning in version 4.1.72,  Ctrl+Shift+A expands cmdlet aliases, parameter aliases and partial parameter names. In earlier versions, Ctrl+Shift+Alt+A expands only cmdlet aliases.
  • The alias expansion features don’t expand aliases that you have defined in your profile. In best practice fashion, just like your users, the PowerShell Studio Editor window does not have access to your profile.
  • The alias expansion features don’t recognize aliases that you have defined in your script. (You really shouldn’t define aliases in a script anyway.)

 

June Blender is a technology evangelist at SAPIEN Technologies, Inc. You can reach her at This email address is being protected from spambots. You need JavaScript enabled to view it. or follow her on Twitter at @juneb_get_help.

If you have questions about our products, please post in our support forum.
For licensed customers, use the forum associated with your product in our Product Support Forums for Registered Customers.
For users of trial versions, please post in our Former and Future Customers - Questions forum.
Copyright © 2024 SAPIEN Technologies, Inc.