PowerShell v3 Alias – New Commands

New Aliases in PowerShell v3PowerShell v3 Alias

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

 ♣

Get-Alias: Count

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"

v4 Result:
PowerShell version 4 has 150 aliases.

v3 Result:
PowerShell Version 3 has 148 aliases.

Repeat for PowerShell v 2
v2 Result:
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).

List Each Alias’s DisplayName

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

Clear-Host
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
Alias-> DisplayName
———————-
%->Foreach-Object
?->Where-Object
ac->Add-Content
asnp->Add-PSSnapin
cat->Get-Content

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.

Guy Recommends:  A Free Trial of the Network Performance Monitor (NPM)Review of Orion NPM v11.5 v11.5

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.

Download a free trial of Solarwinds’ Network Performance Monitor

Compare-Object Reveals 11 New PowerShell Aliases

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.

Clear-Host
$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
InputObject 				   SideIndicator 
--------------------------- -------------
cnsn->Connect-PSSession =>
dnsn->Disconnect-PSSession =>
irm->Invoke-RestMethod =>
iwr->Invoke-WebRequest =>
npssc->New-PSSessionConfigurationFile =>
rcsn->Receive-PSSession =>
rujb->Resume-Job =>
shcm->Show-Command =>
sls->Select-String =>
sujb->Suspend-Job =>
trcm->Trace-Command =>

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.

See more on Compare-Object and -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.

Clear-Host
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

See more on PowerShell Aliases »

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

PowerShell Tutorials   • Introduction   • PowerShell 3 New Aliases   • -Online   • 3 Key Commands

Top 10 PowerShell Aliases   • PowerShell Alias   • PowerShell $_ Variable   • Free CSV Import Tool

PowerShell Parameters   • Cmdlet scripts   • Vista PowerShell   • Windows 8 PowerShell 3.0

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.