Version 3 introduces eleven new shortcuts for regular PowerShell cmdlets, for example 'sls' for Select-String. However, the most interesting part of this page is the journey towards identifying those extra aliases in the latest PowerShell version.
PowerShell New Alias Topics
My idea here is to create a short script, which counts all the aliases. For comparison purposes, it also stamps the result with PowerShell’s major version number.
$Ver = $PSVersionTable.Psversion.Major
$AliasNum = (Get-Alias).count
"PowerShell Version $Ver has $AliasNum aliases"
PowerShell version 4 has 150 aliases.
PowerShell Version 3 has 148 aliases.
Repeat for PowerShell v 2
PowerShell Version 2 has only 137 aliases.
Note 1: To run the above script against PowerShell v2 I created a shortcut thus:
"%windir%\system32\WindowsPowerShell\v1.0\PowerShell.exe " -version 2
Note 2: Pay particular attention to the -version 2 switch. Also note you cannot use this switch with the ISE version of PowerShell. What I did was create a file from the above script with .ps1 extension then I executed the file at the PowerShell command line thus:
D:\PShell\AliasVer (Where AliasVer.ps1 is the filename).
A little research of Get-Alias’s properties reveals that ‘DisplayName’ is the crucial property because it shows both the alias and its underlying PowerShell cmdlet. Discover more properties with Get-Alias | Get Member.
Problem: I could not find a way of getting one script to list the differences between PowerShell v 2 and v 3. For this reason I developed a strategy of creating two physical files, then using Compare-Object to extract the differences.
Get-Alias: Save DisplayName
Get-Alias | Select DisplayName | Out-File "D:\PShell\Alias3DisplayName.txt"
Note 3: Observe the use of Select to filter just one property: DisplayName.
Sample content of file D:\PShell\Alias3DisplayName.txt
Important step: My strategy requires you repeat this step for PowerShell v 2
Employ Replace to Strip Out Spaces
When I first used the two resulting files, Alias3(2)DisplayName.txt, with Compare-Object it did not produce any meaningful results, it seemed to me that white space was getting in the way. For this reason I developed the script below to replace " " (white space) with "" (nothing).
$StrText = Get-Content "D:\PShell\Alias3DisplayName.txt"
$StrText -replace " ", "" | Out-File "D:\PShell\Replace3DName.txt"
Note 4: Since we are dealing with strings, Set-Content would be a viable alternative to Out-File.
SolarWinds’ Network Performance Monitor will help you discover what’s happening on your network. This utility will also guide you through troubleshooting; the dashboard will indicate whether the root cause is a broken link, faulty equipment or resource overload.
What I like best is the way NPM suggests solutions to network problems. Its also has the ability to monitor the health of individual VMware virtual machines. If you are interested in troubleshooting, and creating network maps, then I recommend that you try NPM now.
Recap: We have two files, one containing PowerShell v3 Aliases, the other v2. Our task now is simply to compare them and thus extract a list of new aliases in PowerShell v3.
$Two = Get-Content "D:\PShell\Replace2DName.txt"
$Three = Get-Content "D:\PShell\Replace3DName.txt"
Compare-Object -referenceObject $Two -differenceObject $Three
Result: PowerShell v 3 New Alias List
Note 5: I have used the v2 aliases as the referenceObject, and the v3 aliases as the differenceObject. Observe how the SideIndicator points to the v3 aliases.
Note 6: Compare-Object also has a useful parameter called -SyncWindow; its default is 5. As its name suggests, increasing the window improves the chances of capturing a difference, the only problem is that it takes ages to work through very large files if you employ large values for -SyncWindow.
Example of New PowerShell Alias – SLS
For those learning PowerShell, especially if you are switching from the DOS box, using the old commands such as Ipconfig at the PowerShell command line is a great reason to get started.
Here is an example of combining Select-String’s new alias ‘sls’ with an old favourite command Ipconfig, the result is to add extra value and interest to listing IP addresses.
Ipconfig | sls IPv4
Note 7: As you can see from the above list of new PowerShell aliases, sls means ‘Select-String’.
How to Research More Aliases
There are two classic ways to research aliases, firstly you can get help with syntax by using: Get-Help Get-Alias. Secondly, Get-Member will reveal more properties
# Research Get-Alias Properties
Get-Alias | Get-Member
Note 8: Now we have extra information try:
Get-Alias -definition Select-String
Summary of PowerShell’s New Aliases
Each new version of PowerShell introduces more cmdlets, which in turn bring more Aliases. However, the most interesting part of this page is the technique for getting two lists of aliases, and how comparing them revealed the 11 new aliases in PowerShell v3.
If you like this page then please share it with your friends
See more Microsoft PowerShell tutorials
Please email me if you have a better example script. Also please report any factual mistakes, grammatical errors or broken links, I will be happy to correct the fault.