Drives using providers

The output from Get-PSProvider shows that each provider has one or more drives associated with it.

You can, alternatively, see the list of drives (and the associated provider) using Get-PSDrive, as shown in the following code:

PS> Get-PSDrive

Name Used (GB) Free (GB) Provider Root
---- --------- --------- -------- ----
Alias Alias
C 89.13 89.13 111.64 FileSystem C:
Cert Certificate
D 0.45 21.86 FileSystem D:
Env Environment
Function Function
HKCU Registry HKEY_CURRENT_USER
HKLM Registry HKEY_LOCAL_MACHINE
Variable Variable
WSManWSMan

As providers are presented as a filesystem, accessing a provider is similar to working with a drive. Let's look at the following example:

PS C:> Set-Location Cert:LocalMachineRoot

PS Cert:LocalMachineRoot> Get-ChildItem

Directory: Microsoft.PowerShell.SecurityCertificate::LocalMachineRoot


Thumbprint Subject
---------- -------
CDD4EEAE6000AC7F40C3802C171E30148030C072 CN=Microsoft Root Certif...
BE36A4562FB2EE05DBB3D32323ADF445084ED656 CN=Thawte Timestamping C...
A43489159A520F0D93D032CCAF37E7FE20A8B419 CN=Microsoft Root Author...

A similar approach may be taken to access the registry. By default, drives are available for the current user (HKCU) and local machine (HKLM) hives. Accessing HKEY_USERS is possible by adding a new drive with the following command:

New-PSDrive HKU -PSProvider Registry -Root HKEY_USERS 

After running the command, a new drive may be used:

PS C:> Get-ChildItem HKU:


Hive: HKEY_USERS


Name Property
---- --------
.DEFAULT
S-1-5-19
S-1-5-20
Running HKCU: or Cert: does not change the drive:
Running C: or D: in the PowerShell console changes to a new drive letter. This is possible because C: is a function that calls Set-Location:
(Get-Command C:).Definition
Every letter of the alphabet (A to Z) has a predefined function (Get-Command*:) but the other drives (for example, Cert, HKCU, and so on) do not. Set-Location (or its alias cd) must be used to switch into these drives.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.14.144.108