---
title: "New PSDrive and other PowerShell Drives Save the Day"
description: "Learn how to work with PS drives by creating new drives with the New PSDrive, Get-PSDrive and Remove-PSDrive cmdlets!"
canonical: "https://adamtheautomator.com/new-psdrive/"
---

# New PSDrive and other PowerShell Drives Save the Day

> Learn how to work with PS drives by creating new drives with the New PSDrive, Get-PSDrive and Remove-PSDrive cmdlets!

Source: https://adamtheautomator.com/new-psdrive/

---

ATA Learning

Tap to hide

[

ATA Learning

](/)

*   [Home](/)
*   [Tutorials](/tutorials/)
*   [Instructors](/author/)
*   [Advertising](/advertising/)
*   [Recommended Resources](/resources/)
*   [About Adam](/about-adam/)

Search for:  

*   [](https://twitter.com/adbertram)
*   [](https://github.com/Adam-the-Automator)
*   [](https://www.linkedin.com/company/adam-the-automator-llc)
*   [](/feed/)

![New PSDrive and other PowerShell Drives Save the Day](https://adamtheautomator.com/wp-content/uploads/2021/07/Understanding-and-Building-New-PS-Drives-in-PowerShell.jpg)

# New PSDrive and other PowerShell Drives Save the Day

[![](https://secure.gravatar.com/avatar/2a2b8715aa08761627419c8950b00c8361057d6f2d61f0efd26fad6ce564c02c?s=192&d=mm&r=g)Garry Bargsley](https://adamtheautomator.com/author/garrybargsley/)6 July 20215 min. read

Categories: [IT Ops](/category/it-ops/)

Tags:[PowerShell Language](/tag/powershell-language/)

Table of Contents

*   [Prerequisites](#h-prerequisites)
*   [Inspecting PS Drives with Get-PSDrive](#h-inspecting-ps-drives-with-get-psdrive)
*   [Navigating PS Drives](#h-navigating-ps-drives)
*   [Creating New PS Drives with New PSDrive](#h-creating-new-ps-drives-with-new-psdrive)
*   [Mapping a File Share with New-PSDrive](#h-mapping-a-file-share-with-new-psdrive)
*   [Using a Filesystem PS Drive for the Windows GUI](#h-using-a-filesystem-ps-drive-for-the-windows-gui)
*   [Creating Filesystem PS Drives for Long Directory Paths](#h-creating-filesystem-ps-drives-for-long-directory-paths)
*   [Working with the Registry](#h-working-with-the-registry)
*   [Removing PS Drives with Remove-PSDrive](#h-removing-ps-drives-with-remove-psdrive)
*   [Conclusion](#h-conclusion)

If you’re using PowerShell to work with a file system, registry, certificates, or even network drives, you’ve got to check out [PowerShell drives](https://docs.microsoft.com/en-us/powershell/scripting/samples/managing-windows-powershell-drives?view=powershell-7.1). PowerShell drives or PS drives are a concept in PowerShell that allows you to work with structured data like a file system. The New PSDrive cmdlet is the way to begin.

In this tutorial, you’re going to learn how PS drives work, some of the cmdlets used to work with PS drives, and ultimately how to make your scripting tasks easier.

Open a PowerShell console and let’s get started!

## Prerequisites

This tutorial will be a hands-on demonstration. If you’d like to follow along, be sure you have the following:

*   A Windows PC – Even though PS drives will work in PowerShell on other platforms, all demos will use Windows in this tutorial.
*   An available SMB network share if you’d like to follow along with one of the demos.

## Inspecting PS Drives with `Get-PSDrive`

Out of the box, PowerShell comes installed with a few default drives. To see these drives, run the `Get-PSDrive` command. PowerShell will return various drives from familiar ones like file system drives such as **C** or registry drives like **HKLM** or **HKCU**.

```powershell
Get-PSDrive
```

![Show a list of all PS Drives available to your PowerShell session](https://adamtheautomator.com/wp-content/uploads/2021/07/Get-PsDriveListDefault.png)

Show a list of all PS Drives available to your PowerShell session

PS drives vary in the type of data they contain by _[providers](https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_providers?view=powershell-7.1)_. These providers are what PowerShell uses to expose the data inside each of the drives. You can see above that `Get-PSDrive` has returned drives from eight different providers.

You can find all providers installed on your computer by running `Get-PSProvider`. As you can see below, different providers different [capabilities](https://docs.microsoft.com/en-us/dotnet/api/system.management.automation.provider.providercapabilities?view=powershellsdk-7.0.0#fields) dictating how each provider interacts with the current PowerShell session.

![Finding PSProviders with Get-PSProvider](https://adamtheautomator.com/wp-content/uploads/2021/07/Get-PSProvider.png)

Finding PSProviders with Get-PSProvider

The `Get-PSDrive` also has a few handy parameters such as the `PSProvider` parameter. This parameter allows you to filter the PS drives returned by a particular provider. You’ll see below where `Get-PSDrive` only returns those drives served by the `FileSystem` provider.

```powershell
Get-PSDrive -PSProvider FileSystem
```

![Get-PSDrive limit output to Provider Type](https://adamtheautomator.com/wp-content/uploads/2021/07/Get-PSDriveFileSystem.png)

Get-PSDrive limit output to Provider Type

## Navigating PS Drives

Once you know what PS drives are available, you can then check out what’s inside each of them. For example, the `Env` drive is a default PS drive that contains Windows’ environment variables. Just like with a file system, you can browse environment variables.

To browse the `Env` drive, change to the drive letter with `cd` or [`Set-Location`](https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.management/set-location?view=powershell-7.1) as you normally would a file system and run `ls` or [`Get-ChildItem`](https://adamtheautomator.com/get-childitem/), as shown below.

Related:[Get-ChildItem: Listing Files, Registry and Certificates](https://adamtheautomator.com/get-childitem/)

> _Take note of the colon at the end of each example. You must use a colon to signify a PS drive._

```powershell
cd Env:
ls
```

Once you run `ls`, as shown below, you’ll see PowerShell returns key/value pairs for each environment variable in Windows.

![Inspecting the Env PS Drive](https://adamtheautomator.com/wp-content/uploads/2021/07/EnvListing.png)

Inspecting the Env PS Drive

## Creating New PS Drives with `New PSDrive`

You’ve learned that PowerShell comes with a few built-in PS drives but you can also create custom drives yourself with the `New-PSDrive` cmdlet.

One of the most common uses of the `New-PSDrive` cmdlet is with the `FileSystem` provider to create “shortcuts” to file system directories or even map network drives. Using `New-PSDrive` you can assign labels to various file system locations.

### Mapping a File Share with `New-PSDrive`

For example, perhaps you have an SMB file share on your network somewhere and you need to map that share to a drive letter. You _could_ [map that network drive via the GUI](https://support.microsoft.com/en-us/windows/map-a-network-drive-in-windows-10-29ce55d1-34e3-a7e2-4801-131475f9557d) or you could use PowerShell if you prefer the command-line or your building a script.

In this example, let’s say you have network share located at UNC path `\\localhost\PSDRIVE`.

> _The local computer (`localhost`) is only be used as an example. You can map actual network drives with `New-PSDrive` the same way._

To map a network drive with New PSDrive provide:

*   The `Name` of the drive you’d like to create (`NetShare` in this example).
*   The type of provider (`PSProvider`) the drive will use (`FileSystem` in this example).
*   The path to the file share or `\\localhost\PSDRIVE` using the `Root` parameter.

Run `New-PSDrive`, as shown below, and then run `Get-ChildItem` to see what’s in the file share.

```powershell
New-PSDrive -Name "NetShare" -PSProvider "FileSystem" -Root "\\localhost\PSDRIVE"
Get-ChildItem -Path NetShare:
```

You’ll see that by referencing `NetShare` now is the same as directly referencing `\\localhost\PSDRIVE`.

![Mapping a network drive with New-PSDrive](https://adamtheautomator.com/wp-content/uploads/2021/07/Untitled-74.png)

Mapping a network drive with New-PSDrive

> _Need to assign some notes to your new drive? Perhaps `The file share to store docs`? Use the `Description` parameter like `-Description 'The file share to store docs'`._

#### Using a Filesystem PS Drive for the Windows GUI

In the above example, the PS drive only shows up while in PowerShell. Using New PSDrive in this manner doesn’t technically map a network drive like the GUI does. But, you can still do it by adding the `Persist` parameter.

The `Persist` parameters tells New PSDrive to expose the drive to Windows and just not PowerShell. For example, you could map and `X` drive to the `\\WDMYCLOUD\Garry` file share with the command below.

```powershell
New-PSDrive -Name "X" -PSProvider "FileSystem" -Root "\\WDMYCLOUD\Garry" -Persist
```

You’ll now see the X drive show up in Windows File Explorer.

![File explorer mapped drive displayed](https://adamtheautomator.com/wp-content/uploads/2021/07/NewMappedDriveWindows.png)

File explorer mapped drive displayed

### Creating Filesystem PS Drives for Long Directory Paths

Other than mapping file shares, you can create PS drives with the `New-PSDrive` cmdlet to also save some typing! By creating a drive based on some long directory path, you can get away with changing to a directory called _C:\\thisisareallylongdirectorypath\\Ido\\not\\want\\totype_ to simply _C:\\LongDirPath_.

To demonstrate a real-world example, Microsoft SQL Server2019, by default, stores its logs in the _C:\\Program Files\\Microsoft SQL Server\\MSSQL15.SQL2019\\MSSQL\\Log_ directory. If you routinely find yourself changing to that directory in PowerShell, it would get old quick typing that in every time.

Instead of typing in a long directory path, create a PS drive with `New-PSDrive` called `sqllog`. Once created, then change to the directly not with the original directory path but with the PS drive name.

```powershell
New-PSDrive -Name sqlLog -PSProvider "FileSystem" -Root "C:\Program Files\Microsoft SQL Server\MSSQL15.SQL2019\MSSQL\\og"
Set-Location sqlLog:
```

![Creating a directory "shortcut" with New-PSDrive](https://adamtheautomator.com/wp-content/uploads/2021/07/Untitled-75.png)

Creating a directory “shortcut” with New-PSDrive

### Working with the Registry

PS drives aren’t just relegated to the file system. Remember that PS drives use various providers. One of those providers is the registry. Using the same technique as you’ve learned, you can also create “shortcuts” to any registry key you’d like.

To create PS drives on a registry provider, pass the `Registry` argument to the `PSProvider` parameter and, instead of a directory path, use a registry key path for the `Root`, as shown below. Notice that this example also used the optional `Description` parameter setting a description on the PS drive.

```powershell
New-PSDrive -Name "myRegistry" -PSProvider "Registry" -Root "HKLM\Software" -Description 'my local Registry key'
```

Once created, run `Get-PSDrive` to inspect your work. The below example is using the [`Format-Table`](https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/format-table?view=powershell-7.1) cmdlet to limit output to only the `Name` and `Description` properties. The `Description` property is not visible, by default.

![PS Drive Example with Description](https://adamtheautomator.com/wp-content/uploads/2021/07/PSProvderDescription-1.png)

PS Drive Example with Description

## Removing PS Drives with `Remove-PSDrive`

Finally, perhaps you’re done working with PS drives and it’s time to clean up. To do that, use the [`Remove-PSDrive`](https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.management/remove-psdrive?view=powershell-7.1) cmdlet. One of the most intuitive ways to use the `Remove-PSDrive` cmdlet is to use the PowerShell pipeline. By “piping” PS drives to `Remove-PSDrive`, you can remove or more drives at once.

For example, perhaps you’ve followed all examples in this tutorial and would like to remove them all. Rather than running `Remove-PSDrive` three different times, instead read them all with `Get-PSDrive` and pipe each drive to `Remove-PSDrive`, as shown below.

```powershell
Get-PSDrive -Name NetShare, sqlLog, X | Remove-PSDrive -Force -Scope Global
```

Notice below that each PS drives was created prior but running the above command has removed them all.

> _Note that the `Force` and `Scope` parameters are optional. The `Force` parameter removes a PS drive even if a file is open while `Scope` removes drives defined in the global scope with the `New-PSDrive -Scope` parameter._

![Remove-PSDrive example](https://adamtheautomator.com/wp-content/uploads/2021/07/removePSDriveNames.png)

Remove-PSDrive example

## Conclusion

PS drives can save a lot of time and help you navigate the file system, registry and other data sources easier. Have you been inspired to try out PS drives in your scripts? If so, how?

Share this article

[Share on X](https://twitter.com/intent/tweet?url=https%3A%2F%2Fadamtheautomator.com%2Fnew-psdrive%2F&text=New%20PSDrive%20and%20other%20PowerShell%20Drives%20Save%20the%20Day)[Share on Facebook](https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Fadamtheautomator.com%2Fnew-psdrive%2F)[Share on LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fadamtheautomator.com%2Fnew-psdrive%2F)

## Related Posts

![](https://adamtheautomator.com/wp-content/uploads/2023/08/powershell-approved-verbs.jpg)

### [Your Getting Started Guide to PowerShell Approved Verbs](/powershell-approved-verbs/)

Discover how to get started with PowerShell Approved Verbs to make sure your scripts and code is top-notch in this ATA Learning tutorial!

![](https://adamtheautomator.com/wp-content/uploads/2023/07/powershell-sort-object.jpg)

### [Learning PowerShell Sort-Object with Examples](/powershell-sort-object/)

Learn all of the ins-and-outs of the PowerShell Sort-Object cmdlet in this example driven tutorial by ATA Learning!

![](https://adamtheautomator.com/wp-content/uploads/2023/03/powershell-change-directory.jpg)

### [PowerShell Change Directory: Navigating Your File System](/powershell-change-directory/)

Learn how to use the PowerShell change directory command to navigate your file system with ease. Master the basics of PowerShell file navigation today.

## Categories

*   [IT Ops](/category/it-ops/)
*   [Cloud](/category/cloud/)
*   [DevOps](/category/devops/)
*   [Home Ops](/category/home-ops/)
*   [Information Security](/category/infosec/)
*   [Software Development](/category/software-development/)

## Site

*   [Home](/)
*   [Tutorials](/tutorials/)
*   [Instructors](/author/)
*   [Advertising](/advertising/)
*   [Recommended Resources](/resources/)
*   [About Adam](/about-adam/)

Copyright 2026© ATA Learning | [Privacy Policy](/privacy/)
