Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases now! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Getting Started with Powershell

You're reading from   Getting Started with Powershell Learn the fundamentals of PowerShell to build reusable scripts and functions to automate administrative tasks with Windows

Arrow left icon
Product type Paperback
Published in Aug 2015
Publisher Packt
ISBN-13 9781783558506
Length 180 pages
Edition 1st Edition
Languages
Arrow right icon
Toc

Table of Contents (14) Chapters Close

Preface 1. First Steps FREE CHAPTER 2. Building Blocks 3. Objects and PowerShell 4. Life on the Assembly Line 5. Formatting Output 6. Scripts 7. Functions 8. Modules 9. File I/O 10. WMI and CIM 11. Web Server Administration A. Next Steps
Index

PowerShell aliases

If you tried to use DIR and CD in the last section, you may have noticed that they didn't work exactly as the DOS commands that they resemble. In case you didn't see this, enter DIR /S on a PowerShell prompt and see what happens. You will either get an error complaining about a path not existing, or get a listing of a directory called S. Either way, it's not the listing of files including subdirectories. Similarly, you might have noticed that CD in PowerShell allows you to switch between drives without using the /D option and even lets you change to a UNC path. The point is that, these are not DOS commands. What you're seeing is a PowerShell alias.

Aliases in PowerShell are alternate names that PowerShell uses for both PowerShell commands and programs. For instance, in PowerShell, DIR is actually an alias for the Get-ChildItem cmdlet. The CD alias points to the Set-Location cmdlet. Aliases exist for many of the cmdlets that perform operations similar to the commands in DOS, Linux, or Unix shells. Aliases serve two main purposes in PowerShell, as follows:

  • They allow more concise code on Command Prompt
  • They ease users' transition from other shells to PowerShell

To see a list of all the aliases defined in PowerShell, you can use the Get-Alias cmdlet. To find what an alias references, type Get-Alias <alias>. For example, see the following screenshot:

PowerShell aliases

To find out what aliases exist for a cmdlet, type Get-Alias –Definition <cmdlet> as follows:

PowerShell aliases

Here we can see that the Get-ChildItem cmdlet has three aliases. The first and last assist in transitioning from DOS and Linux shells, and the middle one is an abbreviation using the first letters in the name of the cmdlet.

You have been reading a chapter from
Getting Started with Powershell
Published in: Aug 2015
Publisher: Packt
ISBN-13: 9781783558506
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime