Windows IT Pro is the authoritative and independent resource for windows nt, windows 2000, windows 2003, windows xp. Features a collection of resources and magazines for windows IT professionals.
  
  
  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 


Reader Comments
Hi there.
Great article. All examples worked, at least second time around. I've been following these articles and I enjoy them.
But give the referencesto web-cast on the topic. They are great fun, instrucional and not at least inspirational and motivating.
As for instance Sripting for dummies http://www.microsoft.com/norge/technet/spotlight/sessionh.aspx?videoid=214&PUID=000115874C3F7258 and
Windows, PowerShell, and Windows Management Instrumentation: Unveiling Microsoft's Best Kept Secret - Ben Pearce - 07/08/2008
http://www.microsoft.com/norge/technet/spotlight/sessionh.aspx?videoid=996

Try them. They are great.

Regards,

Martin T
Norway

toremf July 21, 2008 (Article Rating: )


You must log on before posting a comment.

If you don't have a username & password, please register now.




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
Command Prompt Tricks

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

New Microsoft/Yahoo! Deal? No

On Sunday, the Times of London reported that Microsoft had renewed talks with failing Internet giant Yahoo! and would manage its search engine for 10 years, while Yahoo! would retain control of its email, messaging, and content services. This report ...

How can I stop and start services from the command line?

...


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 SQL Server 2008 – Can You Wait? | Philadelphia

PowerShell 101 - eLearning Series

SQL Server 2008 – Can You Wait? | Atlanta

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 Become a VIP member of the Windows IT Pro community!
Get it all with the VIP CD and VIP access. A $500+ value for only $279!

Subscribe to Windows IT Pro!
Solve your toughest technical problems with our experts and access 10,000 + articles online. 30% off

Monthly Online Pass - Only $5.95!
Get instant access to 10,000+ articles from Windows IT Pro Magazine!

TechNet Virtual Labs
Evaluate and test Microsoft's newest products.


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 Windows Dev Pro IT Job Hound ITTV
IT Library Technology Resource Directory Connected Home Windows Excavator Windows SuperSite 
 
 Windows IT Pro is a Division of Penton Media Inc.
 Copyright © 2008 Penton Media, Inc., All rights reserved. Terms and Use | Privacy Statement | Reprints and Licensing