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