Aracılığıyla paylaş


Using the Get-PSDrive Cmdlet

Listing Your Windows PowerShell Drives

Windows PowerShell maps a number of “drives” that make it easy for you to navigate various namespaces on your computer; by default this includes not only the physical disk drives on your computer but also such things as the registry hives HKEY_CURRENT_USER (drive HKCU) and HKEY_LOCAL_MACHINE (drive HKLM). To return a list of all the Windows PowerShell drives on your machine, simply use the Get-PSDrive cmdlet:

Get-PSDrive

In return, Windows PowerShell will return information similar to this:

Name       Provider      Root                                   CurrentLocation
----       --------      ----                                   ---------------
Alias      Alias
C          FileSystem    C:\                                 ...Settings\kenmyer
cert       Certificate   \
D          FileSystem    D:\
E          FileSystem    E:\
Env        Environment
Function   Function
HKCU       Registry      HKEY_CURRENT_USER
HKLM       Registry      HKEY_LOCAL_MACHINE
Variable   Variable

Alternatively, you might want to pipe these results into the Format-List cmdlet; when you do that, you’ll get back additional information (such as the full provider name) for each drive. That command looks like this:

Get-PSDrive | Format-List

And the returned data will look like this:

Name            : Alias
Description     : Drive containing a view of the aliases stored in session state.
Provider        : Microsoft.Windows PowerShell.Core\Alias
Root            :
CurrentLocation :

Name            : C
Description     :
Provider        : Microsoft.Windows PowerShell.Core\FileSystem
Root            : C:\
CurrentLocation : Documents and Settings\kenmyer

You can also specify an individual drive name (or use wildcard characters) to return information about a single drive or set of drives. This command returns information for only drive C:

Get-PSDrive c

And this command returns information for the two registry drives (both of which have names starting with the letter H):

Get-PSDrive h*
Get-PSDrive Aliases
  • gdr