Top 10 PowerShell Aliases for DOS Commands.
I have discovered two types of Alias aficionados. Firstly, there are those who like to use aliases such ‘dir’, ‘cd’ or ‘cls’ in PowerShell, because they used the same commands in DOS. Secondly, there are those who embrace PowerShell aliases such as ‘sort’, ‘type’, or ‘del’ simply to save on typing.
Guy’s Top Ten PowerShell Aliases
- Cd: Set-Location
- Cls: Clear-Host
- Del: Remove-Item
- Diff: Compare-Object
- Dir: Get-ChildItem
- Kill: Stop-Process
- Echo: Write-Output
- Sort: Sort-Object
- Sleep: Start-Sleep
- Type: Get-Content
♣
1) Cd: Set-Location
Incidentally, Set-Location is also known as chdir.
Take every opportunity to search PowerShell cmdlets for aliases by employing the -Definition parameter.
# Research PowerShell’s Aliases
Get-Alias -Definition Set-Location
Note 1: Avoid this trap: plain Get-Alias Set-Location does not work; you need that -Definition parameter.
2) Cls: Clear-Host
I like ‘cls’ for the clarity of having a blank screen when running a second or third script.
3) Del: Remove-Item
PowerShell does not have ‘delete’ in its vocabulary; the verb is always ‘Remove’. Try this experiment:
# PowerShell Remove -v- Delete
Cls
"Remove verbs = " + (Get-Command -Verb Remove).count
"Delete verbs = " + (Get-Command -Verb Delete).count
4) Diff: Compare-Object
Diff, or Compare-Object is a surprisingly useful command for troubleshooting changes.
5) Dir: Get-ChildItem
Get-ChildItem with the -Recurse parameter is the equivalent of dir /s.
6) Echo: Write-Output
Echo is an old technique, not used much in PowerShell. However this is another example of support for DOS (and UNIX) commands.
Guy Recommends: A Free Trial of the Network Performance Monitor (NPM) 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
7) Kill: Stop-Process
Before I use ‘Kill’ or ‘Stop-Process’, I like to use Get-Process just to be sure that Kill is going to do what I expect. Incidentally, this technique also illustrates PowerShell’s pipeline; the output of Get-Process becomes then input for ‘Kill’.
# PowerShell Kill
Cls
Start-Process notepad
Sleep 10
Get-Process Notepad | Kill
Note 2: While this script illustrates Kill, it’s ripe for modification.
8) Sort: Sort-Object
Most of the ‘Object’ family can be abbreviated, because PowerShell has built-in aliases ‘Sort’, ‘Where’, ‘Group’ and ‘Select’.
Warning: While these aliases cut down on typing in your, using this shorthand can cause confusion if other programmers ever need to amend your code. For this reason, I rarely employ shortcuts in my scripts on this site.
9) Sleep: Start-Sleep
Occasionally ‘Sleep’ is useful for pausing scripts, but over the years I find this command is not needed as much as it was in batch files, this is because PowerShell has the intelligence to wait for one command to finish before executing the next instruction.
10) Type: Get-Content
‘Type’ is a classic old programmer’s method of reading the content of text files. These days for such tasks I choose ‘Get-Content, but for those migrating from DOS or VBScript these aliases provide handy stepping stones on the road to PowerShell. See More Aliases in PowerShell v 3.0 »
Guy Recommends: SolarWinds Engineer’s Toolset v10
This Engineer’s Toolset v10 provides a comprehensive console of 50 utilities for troubleshooting computer problems. Guy says it helps me monitor what’s occurring on the network, and each tool teaches me more about how the underlying system operates.
There are so many good gadgets; it’s like having free rein of a sweetshop. Thankfully the utilities are displayed logically: monitoring, network discovery, diagnostic, and Cisco tools. Try the SolarWinds Engineer’s Toolset now!
Download your fully functional trial copy of the Engineer’s Toolset v10
Research More Aliases
# PowerShell See More Aliases
Get-Alias | Sort-Object Definition
PowerShell Alias Family
# PowerShell See More Aliases
Get-Command -Noun Alias
Results:
Name
————-
Export-Alias
Get-Alias
Import-Alias
New-Alias
Set-Alias
Note 3: A special mention for New-Alias, this is handy should you wish to create Aliases for your own scripts. However, be aware such Aliases are not available to other programmers.
More Research into PowerShell’s Cmdlet Aliases
One of the best techniques to discover more about a cmdlets capability is to appending | Get-Member, thus:
# Research Get-Alias Properties
Get-Alias | Get-Member
Filter for DOS or UNIX Aliases
#PowerShell Alias Example
Clear-Host
Get-Alias | Where-Object {$_.Options -NotMatch "ReadOnly"}
Note 4: To list the built-in PowerShell aliases change -NotMatch to -Match
See More About PowerShell’s Aliases »
Summary of PowerShell Top 10 Aliases
I hope that I have not only shown you my favourite aliases, but also given you the tools to research commands that allow you to use PowerShell with even less typing.
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.