---
title: "PowerShell Change Directory: Navigating Your File System"
description: "Learn how to use the PowerShell change directory command to navigate your file system with ease. Master the basics of PowerShell file navigation today."
canonical: "https://adamtheautomator.com/powershell-change-directory/"
---

# PowerShell Change Directory: Navigating Your File System

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

Source: https://adamtheautomator.com/powershell-change-directory/

---

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/)

![PowerShell Change Directory: Navigating Your File System](https://adamtheautomator.com/wp-content/uploads/2023/03/powershell-change-directory.jpg)

# PowerShell Change Directory: Navigating Your File System

[![](https://secure.gravatar.com/avatar/2788bb1a3f735603f81eca51d68daec56a9d97e805a10268fb2c20afcc76b81b?s=192&d=mm&r=g)Nicholas Xuan Nguyen](https://adamtheautomator.com/author/nicholas-xuan-nguyen/)29 March 20239 min. read

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

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

Table of Contents

*   [Prerequisites](#prerequisites)
*   [Switching from One Drive to Another](#switching-from-one-drive-to-another)
*   [Navigating the File System via the cd Command](#navigating-the-file-system-via-the-cd-command)
*   [Moving to a Directory in a Different Drive](#moving-to-a-directory-in-a-different-drive)
*   [Moving One to Many Levels Up in the Directory Hierarchy](#moving-one-to-many-levels-up-in-the-directory-hierarchy)
*   [Moving Into a Specific Subdirectory](#moving-into-a-specific-subdirectory)
*   [Navigating the File System with PowerShell Cmdlets](#navigating-the-file-system-with-powershell-cmdlets)
*   [Setting a Location from a Different Drive](#setting-a-location-from-a-different-drive)
*   [Switching Between Stacked Locations (Push and Pop)](#switching-between-stacked-locations-push-and-pop)
*   [Navigating to a Directory Stored in a Variable](#navigating-to-a-directory-stored-in-a-variable)
*   [Cycling Through Directories in PowerShell’s Location History](#cycling-through-directories-in-powershells-location-history)
*   [Conclusion](#conclusion)

In Windows, changing directories is a fundamental part of file management, but would you settle for writing full paths of each directory you visit? Luckily, PowerShell change directory commands can make your life easier.

In this tutorial, you will explore the commands available to change directories in PowerShell, helping you navigate your file system effortlessly.

Read on and master the basics of file system navigation with PowerShell today!

## Prerequisites

This tutorial will be a hands-on demonstration. To follow along, ensure you have a Windows system with PowerShell installed. This tutorial uses Windows 10 and [PowerShell v7](https://adamtheautomator.com/powershell-7-upgrade/).

Related: [PowerShell 7 Upgrade : A How to Walk Through](https://adamtheautomator.com/powershell-7-upgrade/)

## Switching from One Drive to Another

Each storage device, such as a hard disk or USB drive, is assigned a drive letter (i.e., _C:_, _D:_, _E:_, …_Z:_). When you open a PowerShell window, the prompt is in your user profile directory on the current drive by default.

Suppose you need frequent access to files or folders stored on a different drive than the one you are currently on. If so, switching from one drive to another is necessary.

To see how to switch from one drive to another:

1\. Open PowerShell and confirm if the prompt says _**C:\\Users\\admin**._ If so, then you are currently on the _C:_ drive in the _admin_ user’s profile directory, as shown below.

![powershell change directory - Viewing the default working drive](https://adamtheautomator.com/wp-content/uploads/2023/03/image-230.png)

Viewing the default working drive

2\. Next, open another PowerShell session, but this time, as an administrator.

Related:[Discover How to Run PowerShell as Administrator](https://adamtheautomator.com/powershell-run-as-administrator/)

Below, the prompt starts in a different default directory than launching PowerShell as a regular user. Specifically, the prompt starts in the _System32_ directory within the _Windows_ directory on the current drive (_C:_), as shown below.

This default behavior prevents non-administrative users from accidentally modifying critical system files or running sensitive tools.

![Viewing the default working drive as an admin](https://adamtheautomator.com/wp-content/uploads/2023/03/image-231.png)

Viewing the default working drive as an admin

3\. Run the below command to change the current drive to `D:` (or to any available drive). This syntax is a quick way to navigate between different drives in PowerShell.

```powershell
D:
```

When switching drives in PowerShell with this method, the prompt changes to the root directory of the new drive, as in the output below.

As you can see, regardless of the default directory that PowerShell starts in, you always can switch to another drive.

![Switching to another drive](https://adamtheautomator.com/wp-content/uploads/2023/03/image-232.png)

Switching to another drive

4\. Now, run the below command to attempt switching to the `D:\Kitty` directory (or to any other subdirectory).

```powershell
D:\Kitty
```

Did you get the same error as below? This error shows since you cannot switch to subdirectories (for example, _D:\\Kitty_) in one go by this method.

Jump to the following section to see how to switch to subdirectories.

![Attempting to switch to subdirectories](https://adamtheautomator.com/wp-content/uploads/2023/03/image-233.png)

Attempting to switch to subdirectories

## Navigating the File System via the `cd` Command

Navigating multiple subdirectories is a common task in PowerShell. But is there a quick way to navigate through different subdirectories? Yes! The `cd` command, short for “change directory,” lets you quickly switch to another subdirectory regardless of your current directory.

> _Back in the day, the `cd` command was used to navigate between drives and directories in the Command Prompt. Microsoft made the `cd` command backward compatible so you can still navigate between directories in PowerShell._

Read on and see how to navigate your file system with the `cd` command.

### Moving to a Directory in a Different Drive

Jumping to a subdirectory within a different drive may seem like a hassle if you think about it. Well, there is no need to overthink it. You will be surprised how quickly the `cd` command lets you jump to another drive while moving into one of its directories.

Run the below command to navigate to the subdirectory called _`Kitty`_ in the `D:*` drive.

```powershell
cd D:\Kitty
```

![Navigating a subdirectory in another drive](https://adamtheautomator.com/wp-content/uploads/2023/03/image-234.png)

Navigating a subdirectory in another drive

### Moving One to Many Levels Up in the Directory Hierarchy

With file system management, or when working on a project, you may frequently need to move up one or two levels from your current directory. The cd command supports the `..` notation that lets you effectively switch to the parent directory of your current directory.

This feature lets you move up a level in your file system without specifying the full path to the parent directory.

1\. Run the `cd` command below, append a space and the `..` notation, which tells PowerShell to go up one level in the directory hierarchy.

> _The space character after the `cd` command is not required, as the command will work fine without it. But adding a space is a common practice for better readability and consistency with other commands._

```powershell
cd ..
```

In the output below, you can see the prompt moves up one level from the _**C:\\Users\\admin\\Documents**_ to the _**C:\\Users\\admin**_ directory. Mind you that you did not have to specify the full path for the _**C:\\Users\\admin**_ directory to move up.

![Moving up one level in the directory hierarchy](https://adamtheautomator.com/wp-content/uploads/2023/03/image-235.png)

Moving up one level in the directory hierarchy

2\. Instead of moving one level up, run the following command with two `..` notations, appending a backslash (`\`) at the end of each. Doing so lets you move up two levels in the directory hierarchy.

```powershell
cd ..\..\
```

Below, the output shows you jumped from the _**C:\\Users\\admin\\Documents**_ straight to the _**C:\\Users**_ directory.

![Moving up two levels from the current directory](https://adamtheautomator.com/wp-content/uploads/2023/03/image-236.png)

Moving up two levels from the current directory

3\. Lastly, run the command below to move to the root directory of your current drive.

If you got lost in your file system, this command comes in handy as you can quickly jump to the root directory. This command saves your the hassle of running the `cd ..` command multiple times.

```powershell
cd \
```

![Moving up to the root directory](https://adamtheautomator.com/wp-content/uploads/2023/03/image-237.png)

Moving up to the root directory

### Moving Into a Specific Subdirectory

Like moving a level up in the directory hierarchy, moving into a specific subdirectory is also a quick task. Since there might be many subdirectories, appending notations like the previous ones (`..`, and `..\`) will not work, you must specify the subdirectory’s name.

Run the below command to move into one of the subdirectories (`\admin`) in your current directory (`.`).

```powershell
cd .\admin
```

Notice below that you saved time and effort since you did not have to specify the full path of the _**C:\\Users\\admin**_ directory.

![Moving into one of the subdirectories](https://adamtheautomator.com/wp-content/uploads/2023/03/image-238.png)

Moving into one of the subdirectories

## Navigating the File System with PowerShell Cmdlets

Although the `cd` command undoubtedly works in PowerShell, Microsoft has introduced many cmdlets, like `Set-Location`, that let you navigate through your file system.

These cmdlets provide more robust functionality than the `cd` command that you can use to switch between drives, navigate stacked locations, and cycle through directories in the location history.

Stay tuned and witness how powerful PowerShell cmdlets are in navigating your file system.

### Setting a Location from a Different Drive

Like the `cd` command, the [`Set-Location` cmdlet](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.management/set-location?view=powershell-7.3) allows you to jump from one directory to another and navigate straight to one of its directories. But since you are using a PowerShell cmdlet, you must append the `-Path` parameter to set the path of your target location.

The `Set-Location` cmdlet sets the current working directory to a specified location. That specified location can be one of the following:

*   A directory, or subdirectory on the local file system.
*   Any other location supported by a provider in PowerShell.
*   Or a registry location.

To see how the `Set-Location` cmdlet works in navigating your file system:

Run the below command to navigate to the `Kitty` directory in your `D:` drive specified in the `-Path` parameter.

```powershell
Set-Location -Path "D:\Kitty"
```

![Navigating to a directory in another drive](https://adamtheautomator.com/wp-content/uploads/2023/03/image-239.png)

Navigating to a directory in another drive

> _If you feel a bit lazy typing the full `Set-Location` cmdlet, you can also use one of its [aliases](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_aliases), like `chdir` and `sl`, to navigate your file system. Aliases provide a more convenient way to access frequently used commands._

Now, run the below command to set the working location to a specific registry location. In this case, the `HKLM:\` path (a shorthand) refers to the _HKEY\_LOCAL\_MACHINE_ hive in your Windows Registry.

This command sets the working location to the root of the _HKEY\_LOCAL\_MACHINE_ hive in the registry. Navigating to a registry allows you to access and modify its subkeys and values via other PowerShell commands.

```powershell
Set-Location -Path "HKLM:\”
```

![Setting the working location to a specific registry location](https://adamtheautomator.com/wp-content/uploads/2023/03/image-240.png)

Setting the working location to a specific registry location

### Switching Between Stacked Locations (Push and Pop)

Quickly accessing stacked locations sounds convenient. But is it possible? Yes! The [`Push-Location`](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.management/push-location?view=powershell-7.3) and [`Pop-Location`](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.management/pop-location?view=powershell-7.3) cmdlets let you push and pop locations in a last-in-first-out (LIFO) order from a named stack.

To navigate stacked locations, follow these steps:

1\. Run the below `Push-Location` command to push your current location to a stack called `Paths` and set the `C:\Program Files\PowerShell\` directory as the current directory.

```powershell
Push-Location -Path 'C:\Program Files\PowerShell\' -StackName "Paths"
```

![Pushing the current location to a stack called Paths](https://adamtheautomator.com/wp-content/uploads/2023/03/image-241.png)

Pushing the current location to a stack called Paths

2\. Next, run the command below to push your current location (_C:\\Program Files\\PowerShell\\_) to the top of the same `Paths` stack.

```powershell
Push-Location -Path 'C:\Program Files\WindowsPowerShell\' -StackName "Paths"
```

![](https://adamtheautomator.com/wp-content/uploads/2023/03/image-242-1024x57.png)

3\. Run each command below to set `Paths` as the default stack and view (`Get-Location`) the stacked locations.

```powershell
# Sets the Paths stack as default
Set-Location -StackName "Paths"
# View all stacked paths in the default stack
Get-Location -Stack
```

Below, you can see you currently have two locations stacked, where the last location you pushed is at the top.

![Viewing stacked locations in the Paths stack](https://adamtheautomator.com/wp-content/uploads/2023/03/image-243.png)

Viewing stacked locations in the Paths stack

4\. Now, run the following `Pop-Location` command twice to pop the top stacked location from the default stack, which currently is the Paths stack.

```powershell
Pop-Location
```

![Changing the current directory by popping stacked locations ](https://adamtheautomator.com/wp-content/uploads/2023/03/image-244.png)

Changing the current directory by popping stacked locations

Note that popping the location from the stack removes the location from the stack. The error below indicates that you have popped all stacked locations from the default stack.

![Attempting to view an empty stack](https://adamtheautomator.com/wp-content/uploads/2023/03/image-245.png)

Attempting to view an empty stack

### Navigating to a Directory Stored in a Variable

You have gone through different ways to navigate directories in your file system. But what if you need to navigate a specific location frequently? Typing full paths multiple times or cycling through the location history can be tedious. Why not store a directory’s full path in a variable instead?

With a declared variable, you can navigate to your target directory without specifying the path off the top of your head.

1\. Run the below commands to store the `C:\Program Files\PowerShell\` directory to the `$psh` variable, and set that location (`$psh`) as the current directory.

```powershell
# Store a directory path to a variable
$psh = 'C:\Program Files\PowerShell\'
# Set the directory from the $psh variable as the current directory
Set-Location -Path $psh
```

The output below confirms successful directory change using a variable. Regardless of your current directory, you can quickly navigate to the _C:\\Program Files\\PowerShell\\_ directory via the `$psh` variable.

But note that this method only works for the current PowerShell session unless you persist the variable, as demonstrated in the following step.

![Navigating to a location stored in a variable](https://adamtheautomator.com/wp-content/uploads/2023/03/image-246.png)

Navigating to a location stored in a variable

2\. Next, run the below commands, which do not provide output, but persist the `ev_psh` variable as an environment variable (`SetEnvironmentVariable`) with the value of the directory’s full path.

```powershell
# Add psh as an environment variable
[System.Environment]::SetEnvironmentVariable('ev_psh', 'C:\Program Files\PowerShell\', 'Machine')
# Reload the newly-added environment variable (ev_psh)
$Env:ev_psh = [System.Environment]::GetEnvironmentVariable("ev_psh","Machine")
```

Related:[PowerShell Environment Variables: The Ultimate Guide](https://adamtheautomator.com/powershell-environment-variables/)

3\. Lastly, run the below command to set the value from the `ev_psh` environment variable as the current directory. Ensure that you are in a different directory than the one in your `ev_psh` variable.

```powershell
Set-Location -Path $env:ev_psh
```

![Setting the value of an environment variable as the current directory](https://adamtheautomator.com/wp-content/uploads/2023/03/image-247.png)

Setting the value of an environment variable as the current directory

### Cycling Through Directories in PowerShell’s Location History

Another quick way to cycle through directories in PowerShell is using the location history. The `-Path` parameter tells the `Set-Location` cmdlet to navigate to another directory from the location history (previous and following), depending on the specified value (`-` or `+`).

Related:[How to Use PowerShell History Feature](https://adamtheautomator.com/powershell-history/)

To cycle through directories in PowerShell’s location history:

Run the following commands set locations from the history as the current directory. The `+` character takes you forward in location history, while the `-` character takes you back.

```powershell
# Sets the system root directory as the current directory 
Set-Location -Path $env:SystemRoot

# Navigates back to the previous directory in history (certificate provider)
Set-Location -Path -

# Navigates back to the previous directory in history again (system root directory)
Set-Location -Path -

# Navigates forward to the following working directory in history (certificate provider)
Set-Location -Path +

# Navigates forward to the following working directory in history (HKEY_LOCAL_MACHINE hive)
Set-Location -Path +
```

![Cycling through locations in the location history](https://adamtheautomator.com/wp-content/uploads/2023/03/image-248.png)

Cycling through locations in the location history

## Conclusion

File system navigation can be tricky when your options are limited. But with PowerShell change directory commands, like `Set-Location`, you have plenty of options. How you wish to navigate your file system more efficiently is entirely up to you.

In addition, mastering the use of `Push-Location` and `Pop-Location` to save and recall recent locations is a valuable skill.

These techniques allow you to move quickly and seamlessly through directories and locations in PowerShell. But to further improve, why not consider learning about additional commands, like [`Get-ChildItem`](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.management/get-childitem?view=powershell-7.3), which can save you plenty of time in your daily tasks?

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

Share this article

[Share on X](https://twitter.com/intent/tweet?url=https%3A%2F%2Fadamtheautomator.com%2Fpowershell-change-directory%2F&text=PowerShell%20Change%20Directory%3A%20Navigating%20Your%20File%20System)[Share on Facebook](https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Fadamtheautomator.com%2Fpowershell-change-directory%2F)[Share on LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fadamtheautomator.com%2Fpowershell-change-directory%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/02/powershell-write-output.jpg)

### [PowerShell Write-Output: Your Friendly Output Companion](/powershell-write-output/)

Learn all of the ins and outs of the PowerShell Write-Output cmdlet and take control of script and object output in this ATA Learning tutorial!

## 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/)
