PowerShell Logo Small

Get-PSDrive



This is the built-in help made by Microsoft for the command 'Get-PSDrive', in PowerShell version 3 - as retrieved from Windows version 'Microsoft Windows Server 2012 Standard' PowerShell help files on 2016-06-23.

For PowerShell version 3 and up, where you have Update-Help, this command was run just before creating the web pages from the help files.

SYNOPSIS

Gets drives in the current session.

SYNTAX


Get-PSDrive [[-Name] <String[]>] [-PSProvider <String[]>] [-Scope <String>] [-UseTransaction] [<CommonParameters>]
Get-PSDrive [-LiteralName] <String[]> [-PSProvider <String[]>] [-Scope <String>] [-UseTransaction] [<CommonParameters>]



Search powershellhelp.space

DESCRIPTION


The Get-PSDrive cmdlet gets the drives in the current session. You can get a particular drive or all drives in the session.


Get-PSDrive gets the following types of drives:


-- Windows logical drives on the computer, including drives mapped to network shares.


-- Drives exposed by Windows PowerShell providers (such as the Certificate:, Function:, and Alias: drives) and the HKLM: and HKCU: drives that
are exposed by the Windows PowerShell Registry provider.


-- Session-specified temporary drives and persistent mapped network drives that you create by using the New-PSDrivecmdlet.


Beginning in Windows PowerShell 3.0, the Persist parameter of the New-PSDrive cmdlet can create mapped network drives that are saved on the
local computer and are available in other sessions. For more information, see New-PSDrive.


Also, beginning in Windows PowerShell 3.0, when an external drive is connected to the computer, Windows PowerShell automatically adds a
PSDrive to the file system that represents the new drive. You do not need to restart Windows PowerShell. Similarly, when an external drive is
disconnected from the computer, Windows PowerShell automatically deletes the PSDrive that represents the removed drive.



<

RELATED LINKS

Online Version: http://go.microsoft.com/fwlink/?LinkID=113327
Get-Command
Get-Help
Get-Member
New-PSDrive
Remove-PSDrive
about_Providers

REMARKS

<

Examples


-------------------------- EXAMPLE 1 --------------------------

PS C:\>Get-PSDrive
Name Provider Root
---- -------- ----
Alias Alias
C FileSystem C:\
cert Certificate \
D FileSystem D:\
Env Environment
Function Function
HKCU Registry HKEY_CURRENT_USER
HKLM Registry HKEY_LOCAL_MACHINE
Variable Variable
X FileSystem X:\



This command gets the drives in the current session.

The output shows the hard drive (C:) and CD-ROM drive (D:) on the computer, the drives exposed by the Windows PowerShell providers (Alias:,
Cert:, Env:, Function:, HKCU:, HKLM:, and Variable:), and a drive mapped to a network share (X:).




-------------------------- EXAMPLE 2 --------------------------

PS C:\>Get-PSDrive D
Name Provider Root
---- -------- ----
D FileSystem D:\



This command gets the D: drive on the computer. Note that the drive letter in the command is not followed by a colon.




-------------------------- EXAMPLE 3 --------------------------

PS C:\>Get-PSDrive -PSProvider FileSystem
Name Provider Root
---- -------- ----
C FileSystem C:\
D FileSystem D:\
X FileSystem X:\
Y FileSystem \\Server01\Public
Z FileSystem C:\Windows\System32



This command gets all of the drives that are supported by the Windows PowerShell FileSystem provider. This includes fixed drives, logical
partitions, mapped network drives, and temporary drives that you create by using the New-PSDrive cmdlet.




-------------------------- EXAMPLE 4 --------------------------

PS C:\>if (!(Get-PSDrive X)) {
New-PSDrive -Name X -PSProvider Registry -Root HKLM:\Network
}
else { Write-Host "The X: drive is already in use." }



This command checks to see whether the X drive is already in use as a Windows PowerShell drive name. If it is not, the command uses the
New-PSDrive cmdlet to create a temporary drive that is mapped to the HKLM:\Network registry key.




-------------------------- EXAMPLE 5 --------------------------

PS C:\>Get-PSDrive -PSProvider FileSystem
PS C:\>Get-PSDrive -provider FileSystem
Name Provider Root
---- -------- ----
C FileSystem C:\
D FileSystem D:\
X FileSystem X:\
Y FileSystem \\Server01\Public
Z FileSystem C:\Windows\System32
PS C:\>net use
New connections will be remembered.
Status Local Remote Network
-------------------------------------------------------------------------------
X: \\Server01\Public Microsoft Windows Network
PS C:\>[System.IO.DriveInfo]::getdrives()
Name : C:\
DriveType : Fixed
DriveFormat : NTFS
IsReady : True
AvailableFreeSpace : 39831498752
TotalFreeSpace : 39831498752
TotalSize : 79900368896
RootDirectory : C:\
VolumeLabel :
Name : D:\
DriveType : CDRom
DriveFormat :
IsReady : False
AvailableFreeSpace :
TotalFreeSpace :
TotalSize :
RootDirectory : D:\
VolumeLabel :
Name : X:\
DriveType : Network
DriveFormat : NTFS
IsReady : True
AvailableFreeSpace : 36340559872
TotalFreeSpace : 36340559872
TotalSize : 36413280256
RootDirectory : X:\
VolumeLabel : D_Drive
PS C:\>get-wmiobject win32_logicaldisk
DeviceID : C:
DriveType : 3
ProviderName :
FreeSpace : 39831252992
Size : 79900368896
VolumeName :
DeviceID : D:
DriveType : 5
ProviderName :
FreeSpace :
Size :
VolumeName :
DeviceID : X:
DriveType : 4
ProviderName : \\server01\public
FreeSpace : 36340559872
Size : 36413280256
VolumeName : D_Drive
PS C:\>get-wmiobject win32_networkconnection
LocalName RemoteName
-------------- ------------
x: \\server01\public



This example compares the types of file system drives that are displayed by Get-PSDrive to those displayed by using other methods. This
example demonstrates different ways to display drives in Windows PowerShell, and it shows that temporary, session-specific drives created by
using the New-PSDrive cmdlet are accessible only in Windows PowerShell.

The first command uses Get-PSDrive to get all of the file system drives in the session. This includes the fixed drives (C: and D:), a mapped
network drive (X:) that was created by using the Persist parameter of New-PSDrive, and two temporary Windows PowerShell drives (Y: and Z:)
that were created by using New-PSDrive without the Persist parameter.

A "net use" command, which displays Windows mapped network drives, displays only the X drive. It does not display the Y: and Z: drives that
were created by New-PSDrive. It shows that the X: drive is also mapped to \\Server01\Public.

The third command uses the GetDrives method of the Microsoft .NET Framework System.IO.DriveInfo class. This command gets the Windows file
system drives, including drive X:, but it does not get the temporary drives created by New-PSDrive.

The fourth command uses the Get-WmiObject cmdlet to get the instances of the Win32_LogicalDisk class. It returns the C:, D:, and X: drives,
but not the temporary drives created by New-PSDrive.

The last command uses the Get-WmiObject cmdlet to display the instances of the Win32_NetworkConnection class. Like "net use", it returns only
the persistent X: drive that was created by New-PSDrive.