Part 2 of the PowerShell tutorial for Windows admins introduces aliases and drives.
Latest posts by Timothy Warner (see all)
Contents of this article

In the first part of this miniseries on Windows PowerShell terminology for administrators we briefly described what PowerShell is an introduced you to the cmdlet and the pipeline.

Let’s now continue our journey by learning two additional core terms that every PowerShell scripter should know.

Aliases ^

One of the things that I really love about Windows PowerShell is how much thought the Microsoft developers put into making the environment as user-friendly for existing Windows (and even *NIX) scripters as possible. To me, aliases represent the best example of this universality aspect of Windows PowerShell.

For instance, recall how earlier in this article I told you that the Get-ChildItem cmdlet is analogous in functionality to the Windows dir command? Well, as it happens, you can use dir all day long to retrieve directory listings in PowerShell. Are you a Mac or a NIX scripter? No problem—try using ls. It works!

In PowerShell, an alias is nothing more than a persistent mapping of a system- or user-defined shortcut to a known PowerShell cmdlet.

To obtain a full list of built-in aliases, simply invoke the cmdlet Get-Alias from your PowerShell environment.

PowerShell Tutorial - Aliases

Listing PowerShell aliases

Notice in the above exhibit that when you type cls to clear the screen, PowerShell actually invokes the Clear-Host cmdlet. You can define your own aliases as well by using the Set-Alias cmdlet. The kernel idea here is that over time you can develop a completely tricked-out, personalized scripting environment that is tuned to your intuitive workflow and command preferences.

Drives ^

As I previously mentioned, Windows PowerShell is built atop the .NET Framework. With PowerShell you can reach literally any aspect of local and/or remote computers, including the file system, the Registry, Windows Management Instrumentation (WMI) values, and the Active Directory Services Interface (ADSI).

According to Microsoft, a Windows PowerShell drive is a logical data store location that maps a logical name within PowerShell to a “real, live” data provider. Those data store locations can be:

  • Local or remote filesystems
  • Digital certificates
  • Environment variables
  • Registry keys and/or values

You can invoke the PowerShell cmdlet Get-PSDrive to obtain a list of currently loaded PowerShell drives on the local system. If you want to create a new PowerShell drive, then use the New-PSDrive cmdlet. The following exhibit demonstrates how we can define a virtual drive that maps to a remote file share.

PowerShell Tutorial - Drives

Figure 2: Defining a new PowerShell drive

In the preceding example, the alias remotedocs represents the \\srv1\documents remote file share. We can access the new PowerShell drive by using the command dir remotedocs.

Conclusion ^

At this point you should have a pretty good grasp of basic Windows PowerShell terminology. I will leave you with a laundry list of resources that I hope you will find helpful for further study in PowerShell. In the meantime, if there are other PowerShell-related topics that on which you would like to see coverage here at 4sysops, then please leave your request in the comments. Thanks! Next in this series you will learn how to run a PowerShell script.

For Further Study:

Join the 4sysops PowerShell group!

Your question was not answered? Ask in the forum!

0
Share
1 Comment
  1. Srikanth 8 years ago

    I have mapped a drive using new-psdrive....How can I use that drive (means viewing, using the contents of the drive)

    0

Leave a reply

Your email address will not be published. Required fields are marked *

*

© 4sysops 2006 - 2020

CONTACT US

Please ask IT administration questions in the forums. Any other messages are welcome.

Sending

Log in with your credentials

or    

Forgot your details?

Create Account