Windows IT Pro is the leading independent community for IT professionals deploying Microsoft Windows server and client applications and technologies.
  
  
  Advanced Search 


July 2008

PowerShell 101, Lesson 6

How to work with PowerShell's built-in drives and create new drives
RSS
Subscribe to Windows IT Pro | See More Systems Administration Articles Here | Reprints | Or get the Monthly Online Pass—only $5.95 a month!

Executive Summary:

In Windows PowerShell, providers facilitate access to data stores, such as the Windows file system and registry. Despite their important role, providers are, for the most part, invisible to you within PowerShell. What are visible, however, are the PowerShell drives you use to access the providers. In this lesson, you'll learn about the available drives and how to implement them.

In Windows PowerShell, you access folders and files by providing a pathname, such as C: Windows\System32. In this case, the pathname begins with C, which is the drive name. Whenever you access a file-system resource, you must provide the drive name, or the drive must be implicit within the context of the command, such as when you’re retrieving a list of objects in the current working location.

File-system drives aren’t the only type of drives that PowerShell supports. PowerShell supports a number of drives that provide access to different data stores. For example, as I demonstrated in Lesson 5, you use the Variable drive to access built-in variables and the Env drive to access environment variables.

In this last lesson of the PowerShell 101 series, you’ll learn about the available drives and how to implement them through PowerShell providers that facilitate access to the data stores. You’ll also learn how to work with PowerShell’s built-in drives and how to create additional drives. By the end of the lesson, you’ll know how to access not only the file system but also the certificate store, the registry, and other data stores.

Understanding PowerShell Providers
At the heart of data-store access lies the PowerShell providers. A provider is a Microsoft .NET program that provides a data-access layer between PowerShell and the data. Providers abstract data access so that you can use the same mechanisms within PowerShell to interact with the various stores. For example, you can use the Get-ChildItem cmdlet to access the file system, registry, and certificate store.

PowerShell supports a number of built-in providers. To view a list of providers currently available on your system, you can use the Get-PSProvider cmdlet in the command

Get-PSProvider | select Name

Table 1 lists the providers that currently ship with Power- Shell. Because PowerShell is extensible, custom providers can be developed to access other types of data stores. You can then install those providers and access the data stores as you would access the data stores supported by the built-in providers. However, a discussion about custom providers is beyond the scope of this article. See the about_provider Help file for information.

Despite the important role that providers play, they are, for the most part, invisible to you within PowerShell. What are visible, however, are the PowerShell drives you use to access the providers.

Working with the Built-In Drives
Providers expose data through one or more PowerShell drives. For example, the File- System provider exposes file-system data through PowerShell drives that have a direct correlation to your Windows drives. For instance, the FileSystem provider exposes your Windows C drive through the Power- Shell C drive.

To view a list of PowerShell drives and their associated providers, you can use the Get-PSDrive cmdlet, as shown in the statement

Get-PSDrive | sort Provider, Name

This statement sorts the results first by provider, then by name so that the providers are grouped together, as Figure 1 shows. Notice that on my system, the FileSystem provider supports six drives, the Registry provider supports two drives, and the other providers each support only one drive.

The preceding statement also displays root information. The root refers to the location within the target data store that the PowerShell drive maps to. For example, the HKCU drive maps to the HKEY_ CURRENT_USER hive in the registry. For drives that access nonhierarchical data stores, such as PowerShell aliases and variables, the root value is blank.

You can also use Get-PSDrive to retrieve information about a specific drive. For example, the following statement retrieves data about the Function drive:

Get-PSDrive Function | Format-List

As Figure 2 shows, this statement returns details such as the name of the provider and a description of the drive. Notice that the figure also shows the statement

Get-PSDrive -PSProvider Registry

Continue to page 2

   Previous  [1]  2  3  Next 


Learning Path To read the previous PowerShell 101 lessons, go to
"PowerShell 101, Lesson 1"

"PowerShell 101, Lesson 2"

"PowerShell 101, Lesson 3"

"PowerShell 101, Lesson 4"

"PowerShell 101, Lesson 5"


Top Viewed ArticlesView all articles
What You Need to Know About Microsoft's x64 Server Product Plans

What do Longhorn Server, Windows Compute Cluster Server, and Windows Vista have in common? The x64 platform. ...

Anti-Virus Vendors Prepare for War with Microsoft ... Again

When Microsoft announced its Windows Live OneCare security and PC health product over five years (as MSN OneCare), Symantec, McAfee, and the other consumer-oriented security vendors reacted with stunning vigor. ...

Command Prompt Tricks

One reader shares his tip for setting up the command prompt to reflect a remote path. ...


Related Articles PowerShell Empowerment

Essential Windows PowerShell Commands

PowerShell Scripting

Dig Out by Digging Into PowerShell

Windows OSs Whitepapers Why SaaS is the Right Solution for Log Management

Related Events WinConnections and Microsoft® Exchange Connections

PowerShell 201 - eLearning Series with Paul Robichaux

Check out our list of Free Email Newsletters!

Scripting eBooks Keeping Your Business Safe from Attack: Encryption and Certificate Services

Best Practices for Managing Linux and UNIX Servers

Building an Effective Reporting System

Related Scripting Resources Introducing Left-Brain.com, the online IT bookstore
Looking for books, CDs, toolkits, eBooks? Prime your mind at Left-Brain.com

Discover Windows IT Pro eLearning Series!
Clear & detailed technical information and helpful how-to's, all in our trademark no-nonsense format

Test Drive IT Solutions and Get Free Music Downloads
Solve your toughest IT problems with these free downloads and receive 5 free music downloads!


Windows IT Pro Home Register FAQ for Windows WinInfo News
Europe Edition About Us Contact Us/Customer Service Media Kit Affiliates / Licensing  
SQL Server Magazine Office & SharePoint Pro DevProConnections IT Job Hound ITTV
IT Library Technology Resource Directory Connected Home asp.netPRO Windows SuperSite 
 
 Windows IT Pro is a Division of Penton Media Inc.
 © 2009 Penton Media, Inc. Terms of Use | Privacy Statement | Reprints and Licensing