
Introduction to PowerShell Change Directory
The CD command is an alias of the Set-Location cmdlet used to navigate through the file system and change the working directory. It takes a directory name as an argument and changes the working directory to that directory. We can use either relative or absolute path names as arguments to navigate to a specific directory.
To change the current directory in PowerShell, you can use the Set-Location
cmdlet, also known as the cd
alias. Here is how to CD in PowerShell:
If the directory name contains spaces, you can enclose the folder name in double quotes like this:
Changing to a parent directory
To navigate to the parent directory of the current working directory, you can use the double-dot (..
) notation, like this:
Similarly, Instead of moving one level up, you can move two levels by appending a backslash (\) at the end of each.
To reach the root drive, use:
This will set the current working directory to the root drive, such as “C:\”.
Changing to a child directory
The dot (.) represents the current working directory, and we use the backslash (\) as the directory separator. When you execute this command, you change the current working directory to the “Reports” folder.
PowerShell to Navigate to a Folder
To change the directory in PowerShell, you need to provide the path to the desired folder. This path can be either an absolute path (starting from the file system’s root) or a relative path (relative to the current working directory). You can use an absolute path to navigate to a specific folder. An absolute path specifies the entire path from the root directory to the target directory. For example, to navigate to the “Documents” directory on the C: drive, type:
CD C:\Users\username\Documents
Changing to any other folder is possible with Set-Location by passing the path parameter to it:
Set-Location -Path C:\Scripts
You can also use relative paths to navigate to a directory. A relative path specifies the path from the current working directory to the target directory. For example, to navigate to a directory named “Data” that is located in the “Documents” directory, you can use a relative path like this:
Auto-Completion: Similar to other shells, PowerShell supports auto-completion. Start typing the path and press Tab to complete folder or file names. This tab completion is especially useful when dealing with long directory names.
Using environment variables
Set-Location ${env:ProgramFiles}
This changes the working directory to “C:\Program Files”.
Set-Location (Join-Path -Path $HOME -ChildPath "Documents") # or cd (Join-Path -Path $HOME -ChildPath "Documents")
Push-Location and Pop-Location
You can also the Push-Location
cmdlet (alias pushd
) to temporarily change to a different directory and then use the Pop-Location
cmdlet (alias popd
) to return to the previous directory. This can be useful if you need to perform some tasks in a different directory and then return to the previous location when you are done.
# Change to the D:\Scripts directory Push-Location D:\Scripts # Perform some tasks here # Return to the previous directory Pop-Location
Here is how it works:

Wrapping up
How do I change the current directory in PowerShell?
How do I change from C drive to D drive in PowerShell?
How to change the path in PowerShell?
How do I change the directory in PowerShell when there is a space?
To change the directory in PowerShell, when there is a space in the path, you can enclose the path in double quotes (“”). For example, if the directory is “C:\Program Files”, you would use the command: cd “C:\Program Files”
How do I run a PowerShell script in a specific directory?
How do I change the default directory in PowerShell?
To change the default directory in PowerShell, you can create a PowerShell profile and set the default directory in it. For example, if you want to set the default directory to “C:\Scripts”, you would add “Set-Location C:\Scripts” in the profile file (Create one, if it doesn’t exist already: New-Item -path $profile -type file –force
).
How do I navigate a directory in Windows PowerShell?
How do I navigate to a parent directory?
To navigate to a parent directory, you can use the ..
symbol. For example: Set-Location ..
cd ..
This will move you one level up from the current directory.
How can I quickly navigate to my home directory?
How can I check the current directory in PowerShell?
To check the current directory in PowerShell, you can use the Get-Location
cmdlet or its alias pwd
. For example: Get-Location
How do I list all directories in PowerShell before changing to a new one?
To list all directories in PowerShell, you can use the dir
or ls
command to view all directories and files in your current location.
Table of contents
- Introduction to PowerShell Change Directory
- How to change the Directory in PowerShell?
- Changing the drive in PowerShell
- Setting the default working directory in PowerShell
- Push-Location and Pop-Location
- Viewing the Current Directory in PowerShell
- Tips and tricks for using PowerShell Change Directory Effectively
- Common pitfalls and errors when changing directories in PowerShell
- Wrapping up
Changing the drive in PowerShell
You can also use PowerShell to navigate through different drives on your computer. To navigate to a different drive, you can use the Set-Location cmdlet with the Drive parameter like this:
- Open the PowerShell console.
- Type the drive letter followed by a colon like this – D:
- Press Enter to change to the specified drive.
- You can now navigate through the file system on that drive using the CD command.
Similarly, you can navigate to a folder in another drive using:
Set-Location -Path D:\Scripts #Also works: CD D:\Scripts

In addition, add the “-PassThru” parameter to return the path after PowerShell changes the current working directory. Changing to network drives is also possible. E.g.,
Set-Location \\Fileserver\Public
Provide the UNC path to Set-Location
or cd
.
Setting the default working directory in PowerShell
# Check if profile exists if (-not (Test-Path $profile)) { # Create profile if it doesn't exist New-Item -Type File -Path $profile -Force Write-Host "Profile created at $profile" -ForegroundColor Green } else { Write-Host "Profile already exists at $profile" -ForegroundColor Yellow } # Set the desired default directory $DefaultDirectory = "C:\Scripts" # Append the Change-Location command to the profile Add-Content -Path $profile -Value "Change-Location $DefaultDirectory" Write-Host "Default directory set to $defaultDirectory" -ForegroundColor Green # Inform user to reload their profile or restart PowerShell Write-Host "Please reload your profile or restart PowerShell for changes to take effect." -ForegroundColor Cyan
The working directory should now be set to the directory you specified.
Viewing the Current Directory in PowerShell
If you’re not sure which directory you’re currently in, you can use the command:
You can also use the alias “pwd”, which stands for “print working directory” and will display the current directory path on the command line.
Setting the working directory to the script location in PowerShell
When writing PowerShell scripts, it is often necessary to ensure that the script’s working directory is set to the location where the script is executed. This can be achieved using the Set-Location
cmdlet, which is an alternative to the cd
command.
Set-Location -LiteralPath $PSScriptRoot
Here, the $PSScriptRoot
variable represents the path to the script’s location. By executing this command, the working directory will be set to the script’s location, allowing you to access files and folders relative to the script. You can also get the current path of the script using the automatic variable “$Script:MyInvocation.MyCommand.Path”. E.g.,
#Get path of your current directory location $CurrentPath = Split-Path $Script:MyInvocation.MyCommand.Path -Parent #Get Files and folders in current path Dir $CurrentPath
Tips and tricks for using PowerShell Change Directory Effectively
Now that you know how to use the CD command to navigate through the file system in PowerShell, here are some tips and tricks to help you use it more effectively:
- Use the Tab key to autocomplete the directory and file names. This will save you time and reduce the risk of typos.
- Use the Up Arrow key to quickly recall and reuse previous commands.
- Use the Push-Location command to save the current directory to a stack and navigate to a new directory. You can then use the Pop-Location command to return to the previous directory.
- Use aliases: PowerShell provides aliases for common commands, including
cd
. You can use aliases to save typing time and streamline your workflow. For example, instead of typingcd
, you can use the aliassl
orchdir
to change directories. - Use wildcard characters: PowerShell supports wildcard characters, such as
*
and?
, for pattern matching. You can use wildcard characters to navigate to folders or files with similar names. For example, to change to a folder that starts with “Proj” you can use the following command: “CD Proj*”.
In addition to the basic CD command, PowerShell provides several advanced techniques for changing directories. Here are some of the most useful techniques:
- Use the Join-Path command to combine multiple path components into a single path.
- Use the Resolve-Path command to resolve the full path of a file or directory, even if it contains relative path components.
- Use the Split-Path command to split a path into its parent and child components.
- Use the Test-Path command to test whether a file or directory exists at a specified path.
Common pitfalls and errors when changing directories in PowerShell
While changing directories in PowerShell, you may encounter some common pitfalls and errors. Understanding these pitfalls can help you avoid potential issues and troubleshoot problems effectively. Here are some common pitfalls to watch out for:
- Directory Does Not Exist: If you get an error indicating the directory does not exist, check your spelling and path.
- Invalid characters: PowerShell has specific rules regarding valid characters in folders and file names. If a folder or file name contains invalid characters, you may encounter errors when attempting to change directories. Make sure to use valid characters and escape special characters, if necessary.
- Permissions issues: Some folders or files may have restricted permissions, preventing you from accessing or changing directories. Ensure you have the necessary permissions to navigate to the desired folders or files.
- Missing drives: If you attempt to change to a drive that does not exist or is not currently mounted, you will encounter errors. Make sure to verify the existence and availability of drives before attempting to change them.