- Get-PSDrive
- Syntax
- Description
- Examples
- Example 1: Get drives in the current session
- Example 2: Get a drive on the computer
- Example 3: Get all the drives that are supported by the Windows PowerShell file system provider
- Example 4: Check to see if a drive is in use as a Windows PowerShell drive name
- Example 5: Compare the types of files system drives
- Parameters
- Inputs
- Outputs
- List Hard Drives using Command Prompt & PowerShell in Windows 10
- List Hard Drives using Command Prompt
- List Hard Drives using PowerShell
- How to see all drives available on the computer
- See drives in Windows 10 and Windows 8
- OS & Primary Software (C:)
- DVD RW Drive (D:)
- See available drives in Microsoft Windows 7 and earlier
- 3 1/2 Floppy (A:)
- Local Disk (C:), New Volume (D:), and New Volume (E:)
- Compact Disc (F:)
- See drives in Windows 3.0, 3.1, and 3.11
- See drives in MS-DOS and the Windows command line
- Windows Vista, 7, 8, and 10 command line users
- Other Windows command line and MS-DOS version users
- Change drive letter
- Fdisk
- See drives in the Apple macOS
- See drives in Linux
- Managing Windows PowerShell Drives
- Adding New Windows PowerShell Drives (New-PSDrive)
- Deleting Windows PowerShell Drives (Remove-PSDrive)
Get-PSDrive
Gets drives in the current session.
Syntax
Description
The Get-PSDrive cmdlet gets the drives in the current session. You can get a particular drive or all drives in the session.
This cmdlet gets the following types of drives:
- Windows logical drives on the computer, including drives mapped to network shares.
- Drives exposed by 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-PSDrive cmdlet.
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.
Examples
Example 1: Get drives in the current session
This command gets the drives in the current session.
The output shows the hard drive (C:), CD-ROM drive (D:), and the drives exposed by the Windows PowerShell providers (Alias:, Cert:, Env:, Function:, HKCU:, HKLM:, and Variable:).
Example 2: Get a drive on the computer
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: Get all the drives that are supported by the Windows PowerShell file system provider
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: Check to see if a drive is in use as a Windows PowerShell drive name
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:\SOFTWARE registry key.
Example 5: Compare the types of files system drives
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 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 (G:) that was created by using the Persist parameter of New-PSDrive , and a PowerShell drive (T:) that was created by using New-PSDrive without the Persist parameter.
The net use command displays Windows mapped network drives, in this case it displays only the G drive. It does not display the X: drive that was created by New-PSDrive . It shows that the G: drive is also mapped to \\Music\GratefulDead.
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 G:, but it does not get the drives created by New-PSDrive .
The fourth command uses the Get-CimInstance cmdlet to get the instances of the Win32_LogicalDisk class. It returns the A:, C:, D:, E:, and G: drives, but not the drives created by New-PSDrive .
The last command uses the Get-CimInstance cmdlet to display the instances of the Win32_NetworkConnection class. Like net use, it returns only the persistent G: drive created by New-PSDrive .
Parameters
Specifies the name of the drive.
The value of LiteralName is used exactly as it is typed. No characters are interpreted as wildcards. If the name includes escape characters, enclose it in single quotation marks. Single quotation marks tell Windows PowerShell not to interpret any characters as escape sequences.
Type: | String [ ] |
Position: | 0 |
Default value: | None |
Accept pipeline input: | True |
Accept wildcard characters: | False |
Specifies, as a string array, the name or name of drives that this cmdlet gets in the operation. Type the drive name or letter without a colon (:).
Type: | String [ ] |
Position: | 0 |
Default value: | None |
Accept pipeline input: | True |
Accept wildcard characters: | False |
Specifies, as a string array, the Windows PowerShell provider. This cmdlet gets only the drives supported by this provider. Type the name of a provider, such as FileSystem, Registry, or Certificate.
Type: | String [ ] |
Position: | Named |
Default value: | None |
Accept pipeline input: | True |
Accept wildcard characters: | False |
Specifies the scope in which this cmdlet gets the drives.
The acceptable values for this parameter are:
- Global
- Local
- Script
- a number relative to the current scope (0 through the number of scopes, where 0 is the current scope and 1 is its parent). «Local» is the default.
For more information, see about_Scopes.
Type: | String |
Position: | Named |
Default value: | None |
Accept pipeline input: | True |
Accept wildcard characters: | False |
Inputs
None
You cannot pipe objects to this cmdlet.
Outputs
This cmdlet returns objects that represent the drives in the session.
List Hard Drives using Command Prompt & PowerShell in Windows 10
If you frequently work with the Command Prompt or PowerShell, you may need to copy files from or to an external drive, at such, and many other times, you may need to display the drives within the console window. In this post, we will show you how you can list drives using Command Prompt or PowerShell in Windows 10/8/7.
List Hard Drives using Command Prompt
If you need to simply list the drives, you may use WMIC. Windows Management Instrumentation (WMI) is the infrastructure for management data and operations on Windows-based operating systems.
Open a command prompt, and type the following command:
Press Enter and you will see the list of Drives.
You can also use the following parameter:
Using the following will display Device ID and volume name as well:
Windows also includes an additional command-line tool for file, system and disk management, called Fsutil . This utility helps you list files, change the short name of a file, find files by SID’s (Security Identifier) and perform other complex tasks. You can also use fsutil to display drives. Use the following command:
It will show mapped drives too.
You can also use diskpart to get a list of drives along with some more details. The Diskpart utility can do everything that the Disk Management console can do, and more! It’s invaluable for scriptwriters or anyone who simply prefers working at a command prompt.
Open CMD and type diskpart . Next use the following command:
You will see that the console displays the Volume number and letter, label, formatting type, partition type, size, status, and other information.
List Hard Drives using PowerShell
To display drives using PowerShell, type powershell in the same CMD windows and hit Enter. This will open a PowerShell window.
How to see all drives available on the computer
This page provides information on how to determine which drives and drive letters your computer uses currently. It is not a list of all of the possible drive letters.
See drives in Windows 10 and Windows 8
If you’re running Windows 10 or Windows 8, you can view all mounted drives in File Explorer. You can open File Explorer by pressing Windows key + E . In the left pane, select This PC, and all drives are shown on the right. The screenshot shows a typical view of This PC, with three mounted drives.
OS & Primary Software (C:)
In our first example, the C: and F: drives are hard drives. Most computers only have a C: drive. The hard drive is the primary location where all files are stored on your computer. To open the drive, double-click the drive.
In our example, the drives are labeled «Local Disk» and «New Volume.» A hard drive can be labeled anything and may be different on your computer. For steps on changing the name of your drive, see: How to rename or label a disk drive.
All new computers no longer have a floppy drive (A: or B:) but still start with the C: drive by default. For the history of why a computer starts with the C: drive, see: Why is the hard drive the C: drive?
DVD RW Drive (D:)
The D: drive in this example is the optical disc drive installed in the computer. In most situations, the disc drive will be the last drive letter. If a disc is in the drive, the contents of that disc are shown if you double-click the drive icon.
If the drive AutoPlays the disc, right-click the drive and click Explore.
See available drives in Microsoft Windows 7 and earlier
Microsoft Windows 7, Vista, XP, and earlier users can identify which drives Windows has detected by opening File Explorer and then My Computer, or pressing the Windows key + E shortcut key. The picture is an example of My Computer. As you can see in this example, three different drive types are listed.
In Windows 7 and earlier versions, you can access My Computer (Computer) by double-clicking the icon on the desktop. Or, open the Start menu, and select My Computer or Computer, depending on the version of Windows you’re using.
3 1/2 Floppy (A:)
If the computer has a floppy disk drive, this drive is visible and usually set as the A: drive. If any floppy diskette is in the computer and the A: drive is opened, its contents are shown.
All new computers no longer have a floppy drive (A: or B:) but still start with the C: drive by default. For the history of why a computer starts with the C: drive, see: Why is the hard drive the C: drive?
Local Disk (C:), New Volume (D:), and New Volume (E:)
Next, in our example, the C:, D:, and E: drives are hard drives or hard drive partitions on the computer. Most computers only have a C: drive. The hard drive is the primary location where all files are stored on your computer.
In our example, the drives are labeled «Local Disk» and «New Volume.» A hard drive can be labeled anything and may be different on your computer. For steps on changing the name of your drive, see: How to rename or label a disk drive.
Compact Disc (F:)
Finally, the F: drive in this example is the optical disc drive installed in the computer. In most situations, the disc drive is the last drive letter. If a disc is in the drive, the contents of that disc are shown if you double-click the drive icon.
If the drive AutoPlays the disc, right-click the drive, and click Explore.
See drives in Windows 3.0, 3.1, and 3.11
Windows 3.0, 3.1, and 3.11 users can open drives through the Windows File Manager. In the File Manager, click the drive icons shown above the folder and files. By default, the C: drive will be open. If you want to move to the floppy disk drive, click the A: drive icon. If you’re going to open the CD drive, click the D: CD-ROM drive icon.
See drives in MS-DOS and the Windows command line
Windows Vista, 7, 8, and 10 command line users
If you’re using Windows Vista, 7, or 8, use the wmic command at the Windows command line to view available drives on the computer. At the prompt, type the following command.
Or, for a little more information, such as volume size, use this command:
- See our wmic command page for further information and examples on this command.
Other Windows command line and MS-DOS version users
Unfortunately, there is no easy way to list all available drives on the computer through the MS-DOS prompt with one command. Below are different recommendations for viewing drives.
Change drive letter
Change the drive to an alternate drive letter to determine if a drive is available and ready if no error message is received.
Fdisk
Running the fdisk command allows you to view how the hard drives are set up and configured on the computer. However, this command is only possible if you’re running a version of MS-DOS or Windows that supports fdisk.
- See the fdisk command page for additional information about this command.
Running the vol command on a drive displays the drive label and serial number if available. This command allows you to see what drives are detected.
- See the vol command page for additional information and help with this command.
See drives in the Apple macOS
From the menu bar, select Go, then select Computer, or press the Shift + Command + C keyboard shortcut.
You can also view all drives through the Finder application.
See drives in Linux
Linux users can use the fdisk command to see their partition and drive information.
Managing Windows PowerShell Drives
A Windows PowerShell drive is a data store location that you can access like a file system drive in Windows PowerShell. The Windows PowerShell providers create some drives for you, such as the file system drives (including C: and D:), the registry drives (HKCU: and HKLM:), and the certificate drive (Cert:), and you can create your own Windows PowerShell drives. These drives are very useful, but they are available only within Windows PowerShell. You cannot access them by using other Windows tools, such as File Explorer or Cmd.exe.
Windows PowerShell uses the noun, PSDrive, for commands that work with Windows PowerShell drives. For a list of the Windows PowerShell drives in your Windows PowerShell session, use the Get-PSDrive cmdlet.
Although the drives in the display vary with the drives on your system, the listing will look similar to the output of the Get-PSDrive command shown above.
File system drives are a subset of the Windows PowerShell drives. You can identify the file system drives by the FileSystem entry in the Provider column. (The file system drives in Windows PowerShell are supported by the Windows PowerShell FileSystem provider.)
To see the syntax of the Get-PSDrive cmdlet, type a Get-Command command with the Syntax parameter:
The PSProvider parameter lets you display only the Windows PowerShell drives that are supported by a particular provider. For example, to display only the Windows PowerShell drives that are supported by the Windows PowerShell FileSystem provider, type a Get-PSDrive command with the PSProvider parameter and the FileSystem value:
To view the Windows PowerShell drives that represent registry hives, use the PSProvider parameter to display only the Windows PowerShell drives that are supported by the Windows PowerShell Registry provider:
You can also use the standard Location cmdlets with the Windows PowerShell drives:
Adding New Windows PowerShell Drives (New-PSDrive)
You can add your own Windows PowerShell drives by using the New-PSDrive command. To get the syntax for the New-PSDrive command, enter the Get-Command command with the Syntax parameter:
To create a new Windows PowerShell drive, you must supply three parameters:
A name for the drive (you can use any valid Windows PowerShell name)
The PSProvider (use «FileSystem» for file system locations and «Registry» for registry locations)
The root, that is, the path to the root of the new drive
For example, you can create a drive named «Office» that is mapped to the folder that contains the Microsoft Office applications on your computer, such as C:\Program Files\Microsoft Office\OFFICE11. To create the drive, type the following command:
In general, paths are not case-sensitive.
You refer to the new Windows PowerShell drive as you do all Windows PowerShell drives — by its name followed by a colon (:).
A Windows PowerShell drive can make many tasks much simpler. For example, some of the most important keys in the Windows registry have extremely long paths, making them cumbersome to access and difficult to remember. Critical configuration information resides under HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion. To view and change items in the CurrentVersion registry key, you can create a Windows PowerShell drive that is rooted in that key by typing:
You can then change location to the cvkey: drive as you would any other drive:
The New-PsDrive cmdlet adds the new drive only to the current Windows PowerShell session. If you close the Windows PowerShell window, the new drive is lost. To save a Windows PowerShell drive, use the Export-Console cmdlet to export the current Windows PowerShell session, and then use the PowerShell.exe PSConsoleFile parameter to import it. Or, add the new drive to your Windows PowerShell profile.
Deleting Windows PowerShell Drives (Remove-PSDrive)
You can delete drives from Windows PowerShell by using the Remove-PSDrive cmdlet. The Remove-PSDrive cmdlet is easy to use; to delete a specific Windows PowerShell drive, you just supply the Windows PowerShell drive name.
For example, if you added the Office: Windows PowerShell drive, as shown in the New-PSDrive topic, you can delete it by typing:
To delete the cvkey: Windows PowerShell drive, also shown in the New-PSDrive topic, use the following command:
It’s easy to delete a Windows PowerShell drive, but you can’t delete it while you are in the drive. For example: