1 min read

Categories

Tags

393790664_da5b0ddb12_m Further extending my PowerShell ISE module (ISEUtils) I’ve added a function to convert aliases either in the currently active ISE file or (in case a a path is provided) within any PowerShell file (that way the function can be also used from the PowerShell Console) to their respective definitions. Aliases are very useful when working interactively, since they help saving extra keystrokes when you just want to get things done fast. At the same time if we are speaking about production code where readability, and easy comprehension of the code are much more important the usage of aliases should be avoided ( read here for a good article on best practices for PowerShell alias usage). With the Expand-Alias function you can get the best of both worlds. Writing clearer code while avoiding extraneous keystrokes. For the code samples in my blog posts I’m also using aliases quite a lot, but would like to start using the new function from now on. Below is the source code for Expand-Alias: https://gist.github.com/9db6632423d673ff18f6 Usage:

  1. If the function is called without any parameter it will expand all aliases within the current ISE file.

  2. Providing a full-path to the path parameter will expand all aliases within the respective PowerShell file instead.

Adding the following lines to your PowerShell profile (you can read here and here on how to work with profiles) will automatically load the function and add an item to the AddOn menu to call it on every ISE startup: [code language=”powershell”] $FULLPATHTOEXPANDALIAS = ‘c:\expand-alias.ps1’ . $FULLPATHTOEXPANDALIAS $null = $psISE.CurrentPowerShellTab.AddOnsMenu.Submenus.Add(‘Expand-Alias’, { Expand-Alias }, ‘CTRL+SHIFT+X’) [/code]

shareThoughts


Photo Credit: Martin Gommel via Compfight cc