Get PSDrive - PowerShell


Overview

Get-PSDrive retrieves information about PowerShell drives. It provides details about mapped network drives, special drives, or custom drives created by applications or users.

Syntax

Get-PSDrive [-Name] <string> [-Scope <string>] [-ErrorAction <string>] [-ErrorVariable <string>] [-OutVariable <string>] [-OutBuffer <int>] [-PipelineVariable <string>]

Options/Flags

| Option | Description |
|—|—|
| -Name | Filters results to include only drives with the specified name (wildcards are supported). |
| -Scope | Specifies the scope in which to search for drives. Valid values are Global (all drives), Local (drives available to the current user), or Script (drives created in the current script scope). |
| -ErrorAction | Controls how errors are handled. Valid values are Continue, Stop, SilentlyContinue, or Ignore. |
| -ErrorVariable | Stores any errors that occur during the operation into the specified variable. |
| -OutVariable | Stores the results of the command in the specified variable. |
| -OutBuffer | Sets the number of objects to buffer before writing to the output stream. |
| -PipelineVariable | Specifies the variable used to pass objects to the command from the pipeline. |

Examples

Get information about all drives:

Get-PSDrive

Get information about a specific drive:

Get-PSDrive -Name C:

Get drives within the current script scope:

Get-PSDrive -Scope Script

Filter drives by name:

Get-PSDrive -Name *System*

Common Issues

Drive Not Found: Ensure the provided drive name is correct and exists in the specified scope.

Access Denied: Verify that the user has sufficient permissions to access the drive.

Integration

Combine with Get-Item:

Get-PSDrive | Get-Item

Pipe to Where-Object:

Get-PSDrive | Where-Object {$_.Name -like "N*"}
  • New-PSDrive: Creates a new PowerShell drive.
  • Remove-PSDrive: Removes a PowerShell drive.
  • Set-PSDrive: Modifies properties of an existing PowerShell drive.