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!

In this case, Get-PSDrive returns a list of drives associated with the Registry provider.

After you know what drives are available, you can access those drives within your commands. For example, you can change your working location to the Env drive with the statement

cd Env:\

This statement uses the cd alias to reference the Set-Location cmdlet. Figure 3 shows how the command prompt now reflects the new location. Once in that folder, you can run other PowerShell commands, such as

dir | where {$_.Name -like “*path*”}

In this command, I use the dir alias to reference the Get-ChildItem cmdlet, then filter out all variable names that don’t contain the string path. The results in Figure 3 show that the Get-ChildItem cmdlet works the same as if this were a file-system drive.

You can access any drive type from any other drive type. For example, the following statement retrieves a list of objects in the HKCU drive:

dir HKCU:\

As you can see in Figure 4, Env is still my working location, but the results are pulled from the HKCU drive.

You can also change to any drive type from any drive type. For example, the following command changes the working location to a registry key:

cd HKCU:\Software\Microsoft\Office\

As this command shows, not only can you change to a different drive, but you can also change to folders within that drive, whether it’s in the registry, the file system, or another hierarchical data store. In this case, I’ve set the working location to HKEY_CURRENT_ USER\Software\Microsoft\Office.

It also doesn’t matter whether you access data through different providers or the same provider. For example, the following statement retrieves information from a registry key in a different hive:

dir HKLM:\Software\Microsoft\Office\

By using PowerShell drives, you can jump from location to location without taking any special steps, as shown in Figure 5.

To view specific information about an item such as a registry key, you can use the Get-ItemProperty cmdlet. The following statement retrieves information about the HKEY_LOCAL_MACHINE\Software Microsoft\ASP.NET key:

Get-ItemProperty `
HKLM:\Software\Microsoft\ASP.NET

As you can see in Figure 6, the statement retrieves a list of properties and their values. Notice that the results also include Power- Shell-specific information, such as the name of the PowerShell drive and provider.

Besides using the PowerShell built-in drives to retrieve data, you can use them to take any action applicable to the data store. For example, you can use the New-Item cmdlet to create an object in the registry:

Continue to page 3

   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
2009 Windows IT Pro Editors' Best and Community Choice Awards

Picking a favorite product from an impressive crowd of competitive offerings is never an easy task, and such was the case with our Editors' Best and Community Choice awards this year. ...

Command Prompt Tricks

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

WinInfo Short Takes: Week of November 23, 2009

An often irreverent look at some of the week's other news, including some post-PDC some soul searching, a Google Chrome OS announcement and a Microsoft response, Windows 7 off to a supposedly strong start, the Jonas Brothers and Xbox 360, and so much more ...


Related Articles PowerShell Empowerment

Essential Windows PowerShell Commands

PowerShell Scripting

Dig Out by Digging Into PowerShell

Scripting Whitepapers From Development to Production: Streamlining SharePoint Deployment with DocAve Deployment Manager

Related Events Deep Dive into Windows Server 2008 R2 presented by John Savill

PowerShell 201 - eLearning Series with Paul Robichaux

PowerShell 101 - eLearning Series

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


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
Left-Brain.com Technology Resource Directory asp.netPRO ITTV Windows SuperSite 
 
 Windows IT Pro is a Division of Penton Media Inc.
 © 2009 Penton Media, Inc. Terms of Use | Privacy Statement