PC Slower Than It Used to Be?
A free scan shows the junk files, broken settings and background clutter dragging Windows down - then fixes them in one click.Free scan · Windows 10 & 11Outdated Drivers Are Slowing You Down
One free scan finds every outdated or missing driver and matches the right update for your exact hardware.Free scan · exact hardware matchiTechGuides is reader-supported. When you buy through links on our site, we may earn an affiliate commission. As an Amazon Associate I earn from qualifying purchases. Learn more
Are you new to PowerShell and want to learn PowerShell CD (Set-Location) command? This guide teaches you all you need to know about changing the directory in PowerShell with CD or Set-Location.
Overview

Like the CD (Change Directory) command, Set-Location changes the current working location to a location you specify. Talking about “working location”, this could be a drive letter, path to a folder or registry hive.
In addition to setting the current location to a folder, you could also set it to a subfolder. After setting the current location, you can run commands to target the current location without having to specify the path exclusively in your commands.
For example, if I want to run a PowerShell script in “D:\PowerShell Scripts\Get-Windows11Compatibility”, I will run the command below to set my current location to the folder.
Popular on Amazon
- 【PLUG & PLAY – EASY CONNECTION】 Simply connect the Amicool External DVD Drive to your computer’s USB or Type-C port, and it will usually be detected right away without the need for extra drivers. For stable operation and sufficient power, we recommend connecting it directly to a USB port on your computer (for desktops, use a rear motherboard port) and avoiding USB hubs or extension cables. This user-friendly design ensures quick setup for both beginners and professionals.
- 【FAST & STABLE DATA TRANSMISSION】 Featuring dual interfaces (USB 3.0 and Type-C), this optical drive supports data transfer speeds up to 5Gbps. To ensure a reliable connection, please connect it directly to your computer. The drive supports multiple disc formats such as DVD+R, DVD-R, CD-R, and CD-RW. Please note: It does NOT support DVD-RAM, Blu-ray (BD) discs, or certain proprietary formats. Maximum DVD read speed is 8x, and maximum CD read/write speed is 24x.
- 【UNIVERSAL COMPATIBILITY】 Compatible with Windows 11 / 10 / 8.1 / 7, Linux, and all macOS (Intel & Apple Silicon) for MacBook Air/Pro, iMac, Mac mini; NOT for iPad/iPhone/Apple TV/ChromeOS; for Mac, insert disc FIRST, connect directly to USB port (use a POWERED USB‑C hub for M1/M2/M3 to avoid insufficient power), and open media with VLC Player (Apple DVD Player not supported). Works with most computers from brands like Apple, Dell, HP, Lenovo, ASUS, Acer, and Samsung. 👉 Important: Designed specifically for computers. It is NOT compatible with TVs, tablets, game consoles (e.g., PlayStation, Xbox), car stereos, or standalone Blu-ray players.
- 【SLIM & PORTABLE DESIGN – BUILT-IN CABLE, READY TO GO】With an integrated cable design, slim body, and stylish matte finish, this lightweight CD/DVD drive is both durable and portable. Easily slip it into your laptop bag or backpack and use it anytime, anywhere—perfect for business, travel, or home use
- 【MULTIFUNCTIONAL & RELIABLE OPERATION】 Equipped with intelligent error correction and anti-shock technology, this drive supports reading, writing, and burning discs. If the drive is not recognized or a disc cannot be read, try restarting your computer or testing with a different, standard CD-R or DVD-R disc. The pop-up button and built-in cable design offer convenience and portability. For desktop PCs, connecting to a rear USB port is recommended for optimal power and performance.
Set-Location "D:\PowerShell Scripts\Get-Windows11Compatibility"
Once I set the current location with the CD command, I can run a PowerShell script in that location by adding a period and backslash (.\), followed by the tab key (to select available scripts in the location.

Syntax and Parameters of the Set-Location Command
The Set-Location cmdlet has three syntaxes:
Set-Location [[-Path] <String>] [-PassThru] [-UseTransaction] [<CommonParameters>]
Set-Location -LiteralPath <String> [-PassThru] [-UseTransaction] [<CommonParameters>]
Set-Location [-PassThru] [-StackName <String>] [-UseTransaction] [<CommonParameters>]
In the table below, I have explained each parameter in the Set-Location syntaxes.
| Parameter Name | PowerShell CD (Set-Location) Parameter Meaning/Notes |
|---|---|
| Path | Use the Path parameter to specify the path of a new working location. The Path parameter accepts wildcards. |
| LiteralPath | Use the LiteralPath parameter to specify a path of the location. The value of the LiteralPath parameter is used exactly as it is typed. The difference between the Path and the LiteralPath parameter is that Path accepts wildcards while LiteralPath requires you to specify the exact path. |
| StackName | The StackName parameter specifies an existing location stack name that this cmdlet makes the current location stack. Using CD or Set-Location with the -StackName parameter does not change the current location. It only changes the stack used by the *-Location cmdlets. To list all the *-Location cmdlets, run the command: Get-Command *-Location. More in the examples section. |
| UseTransaction | This is a SwitchParameter – meaning that it does not require you to specify any input. When you use CD or Set-Location with -UseTransaction, PowerShell includes the command in the active transaction. This parameter is valid only when a transaction is in progress. |
| PassThru | Like the UseTransaction parameter, PassThru is also a SwitchParameter. Using this parameter returns a PathInfo object that represents the location. By default, the Set-Location cmdlet does not generate any output. But if you run Set-Location with -PassThru, it displays the PathInfo object of the current working directory. |
PowerShell CD Examples
Welcome to the fun part of this article! In the following subsections, I’ll show you different ways you can use the CD or Set-Location command in PowerShell.
Example 1: Use Set-Location to Change to a Directory (Folder)
You will perform this task with the CD command – changing the current PowerShell location to a directory.
To change to a Directory with CD or Set-Location, use the command syntax below:
CD <folder or directory path>
For example, to change a directory to a folder called “Junctions” in drive D:\, I’ll run the command below:
CD D:\Junctions
The PowerShell prompt will change to the specified directory immediately.

Example 2: Use PowerShell CD Command to Change to a Folder with Spaces
Changing to a folder with spaces is the same as changing to a folder without spaces with one exception. Unlike changing to a folder without spaces, to CD to a folder with spaces, enclose the folder in double quotes (“”).
For example, to change to a folder called “VMWare ESXi” located in drive D:\, I’ll run the command below –
Set-Location "D:\VMWare ESXi"
To show you what would have when you CD to a folder with spaces without enclosing the folder path in quotes, I ran the Set-Location without the quotes. This threw an error message. ]
But when I ran the command and enclosed the folder path in double quotes, the command ran successfully.
Free tools Windows power users keep installed
One-click scans. No signup required.

Example 3: Use Set-Location Cmdlet to Change to Root Directory
The root directory in Windows is the drive letter of a partition. For example, the root directory of “D:\VMWare ESXi” is D:\. To change from the current directory to the root directory, run the CD command (or Set-Location), followed by a space, then add two periods (..).
Also popular on Amazon
- Plug & Play. Easy to use, powered by USB port. No external driver or power adapter needed. Simply plug it into your USB port for automatic detection. For optimal performance on desktop computers, connect directly to a high-power USB port on the back of the motherboard. This hassle-free solution requires no technical setup, and if the drive isn't immediately recognized, trying a different USB port typically resolves most connection issues
- High Speed & Reliable Performance. Compatible with USB 3.0 (backwards compatible with USB 2.0), this drive delivers fast data transfer speeds up to 5Gbps. Engineered with strong fault tolerance, it minimizes freezing, skipping, and errors during disc playback or burning. The stable performance ensures smooth, reliable operation and reduces the risk of defective performance
- Intelligent Tech & Stable Connection. Features a physical eject button that safely releases discs even when your computer fails to recognize the drive—eliminating the common frustration of stuck media. Enhanced with copper mesh technology, this external component ensures consistently stable data transmission during all your reading and writing tasks
- Trendy & Practical Design. Features a brushed texture shell for modern visual and tactile appeal. The innovative embedded cable design keeps your USB cable securely stored and always accessible, eliminating worries about misplacement. This compact, all-in-one solution is perfectly suited for easy transport and organized storage
- Wide Compatibility. This external USB CD/DVD drive works with Windows 11/10/8.1/7/Vista/XP, Linux, and macOS 10.16+ (MacBook Pro/Air, iMac, Mac mini). Compatible with most laptops/desktops (HP, Dell, Lenovo, ASUS, Samsung). For optimal performance on desktops, connect to rear USB ports. Supported formats include CD-ROM/R/RW, DVD-ROM/R±RW/R±DL, and VCD. IMPORTANT: Not compatible with ChromeOS, smartphones, tablets, TVs, projectors, vehicles, or Blu-ray/4K discs. Please verify your device type before purchasing
Here is an example. To change my current directory from “D:\VMWare ESXi” to the root directory, D:\ I’ll run the command below.
CD ..

Apart from changing to the root directory of the current folder, you can also change to the system root directory. The system root directory is the folder in Windows is installed.
To change to the system root directory in PowerShell, run the CD (or Set-Location) command and specify the system root environment variable.
Recommended Free Tools
set-location $env:SystemDrive
When I run the above command on my PC, my PowerShell console changes its current directory to C:\Windows – my system root folder.

How To Use Set-Location Command To Change To Environment Variables
PowerShell has a long list of environment variables. The environment variables start with “$env:”
So, if you’re not sure of the name of environment variable you want to CD into, type $env: – then, press the tab key to display available environment variables.
For example, if I want to CD to “Programe Files” environment variable, I will enter $env: in my PowerShell console. Then, I’ll keep pressing the tab key until my PowerShell console displays “$env:CommonProgramFiles.”
Then, to change my current directory to Programe Files, I’ll press the enter key.

This knowledge has real-life scripting applications. So, next time you’re scripting and you need to CD to an environment variable, you know what to do!
How To Use PowerShell Set-Location To CD To A Network Drive
In Windows, you can access a network drive by entering two backslashes, followed by the name of the network server. Then, you’ll enter another back slash followed by the name of the shared network folder.
So, if you wish to CD to a network drive, you use the same method to define the path to the network share. For example to change directory to a network folder called “Tempfolder4” in a server called “ITGLTUK01”, I’ll run the command below.
CD \\ITGLTUK01\Tempfolder4

Alternatively, if the network share in mapped to a local drive, you can change directory to that local drive. For the network path I used in the last example is mapped to my local drive Z – see the screenshot below.
Also popular on Amazon
- 【Plug & Play】This ORIGBELIE external CD DVD drive is powered by USB port, no additional drivers and power supply required! Just plug the USB type-A or type-C connector on the data cable to your computer and the CD burner will be detected by computer automatically, you can then use the corresponding software to read and write the discs with no complex settings. As for Mac system, please note that the computer will not display the device icon until the disc is placed and read successfully.
- 【High-Speed】The external DVD drive supports USB 3.0 high speed data transmission and is backward compatible with USB 2.0 / 1.1. It delivers max 8x DVD read/write speeds and max 24x CD read/write speeds, provides faster data transfer rates of up to 5 Gbps (625MB/S) without lag or distortion, get more done in less time! It also boasts strong error correction capability, noise reduction, shock resistance and low power consumption.
- 【Wide Compatibility】- This external cd drive supports various devices. It's compatible with Windows 11/ 10 / 8 / 7 / XP / 98 / SE / ME / 2000, Vista 7 / 8, Linux, Mac OS 10.6 or above such as Apple MacBook Air, iMac, Mac Mini and MacBook Pro. For desktops, please connect the DVD burner to the back USB port of the motherboard to avoid power shortage. (Not support for Cars, TV, Tablet, Phones, iPads, PS4/5, Xbox, Switch, Projectors, Chromebook, Surface (some models), Ubuntu system and blu ray disk)
- 【All Kinds of Disc】This CD player for laptop support read and write various formats discs, e.g. CD±R/RW, CD-ROM, DVD±R/RW, DVD-ROM, DVD-RAM, DVD+R DL, DVD-R DL, VCD e SVCD. The CD drive also can be used to listen to music, watch movies, data backup, burn files, install software, operating systems or games. If the CDs or DVDs can't be read by computer, use the charging cable included in the packge to connect to 5V charger or power bank to get extra power, that's because some computer doesn't have enough power to support the operation of the USB DVD drive external.
- 【Ultra Slim and Portable】Measuring just 13mm in thickness and weighing only 0.2 kg, the ORIGBELIE external optical drive is extremely slim and portable, taking up minimal space in travelling bag while on-the-go. Integrated data cable design, no need to worry about cable missing. What's more, its durable construction and anti-skid bottom ensure stable operation.

I can use the PowerShell Set-Location command to CD to drive Z:\.
Set-Location Z:\

Example 4: Use PowerShell Set-Location to CD to Current Script Location
You can only CD to the current script location when you’re running a script. So, you cannot cd to current script location when you run a command on the PowerShell console.
The current script location is defined by a variable called $Script:MyInvocation.MyCommand.Path.
The Tool Desk
Outbyte PC Repair FREEClear out junk files and repair common Windows errorsFree Scan →Outbyte Driver Updater FREEScan for outdated or missing drivers - takes under a minuteDriver Scan →To get the current location of the script you’re running, use the Split-Path command as shown below:
Split-Path -Parent $Script:MyInvocation.MyCommand.Path
However, as I mentioned earlier, if you run this command in a PowerShell, it will return an error. You can only use this command to return the location of the script if the script is running.
So, to demonstrate how this works, I have written a short script that writes the current location of the script. Here is the script…
$ScriptLocation = Split-Path -Parent $Script:MyInvocation.MyCommand.Path Write-Host "This script is located in $ScriptLocation"
In the first line of the code, I saved “Split-Path -Parent $Script:MyInvocation.MyCommand.Path” in a variable. Then, in line two, I used Write-Host to display the information “This script is located in $ScriptLocation”.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
The Write-Host command will replace $ScriptLocation with the information saved in the variable – in this instance, the location of the script I am running.
To run this script, I copied it to a new PowerShell ISE document. Then, I saved the script as scriptpath.ps1.
To run the script, I opened a PowerShell console, navigated to the folder I saved the script, then called the script with…
.\scriptpath.ps1
As shown in the screenshot below, the script displayed “This script is located in D:\PowerShell Scripts,” – confirming that my script is located in “D:\PowerShell Scripts.”
Do these 3 things before closing this tab:
1Repair Windows errors before they cause bigger problems2Scan for outdated or missing drivers - takes under a minute3Clear out junk files and repair common Windows errors
Example 5: Use PowerShell Set-Location to CD to the Current User’s Desktop or Documents Folder
To get the current user’s desktop run the command below:
Also popular on Amazon
- PLUG & PLAY: The external CD DVD drive for laptop comes with an integrated dual-port cable that supports USB-A and USB-C interfaces for wide device compatibility. No extra driver installation or external power supply required for daily use. The device can be effortlessly recognized by mainstream operating systems; please insert a readable disc to activate and display the drive icon if you are using Mac devices, helping you access disc media within seconds with compatible playback and burning software.
- Broad System Compatibility: This USB external CD/DVD drive for pc offers extensive compatibility, working seamlessly with Windows 11, 10, 8.1, 7, Vista, XP, 2000, ME, and 98, alongside most Linux distributions. It supports laptops, desktops, and all-in-one PCs from leading brands including HP, Dell, Lenovo (ThinkPad), ASUS, LG, Samsung, and Microsoft. It is also fully compatible with Apple MacBook Pro, MacBook Air, iMac, and Mac mini/Studio running macOS 10.16 or later. For optimal power stability with desktop computers, connect directly to a rear USB port. Note: Not compatible with ChromeOS (Chromebooks), iPads/tablets, TVs,vehicles (cars/trucks),some Surface models, or Blu-ray/4K discs.
- UPGRADED USB 3.0 TRANSFER PERFORMANCE: USB cd dvd external drive adopting premium USB 3.0 transmission technology to deliver a data transfer speed up to 5Gbps, this portable optical drive maintains stable connectivity and is backward compatible with USB 2.0 and USB 1.1 ports. It supports 8X maximum reading & writing speed for DVDs and 24X for CDs. Built-in upgraded error correction and noise reduction modules effectively reduce data loss and running noise, realizing low-energy and smooth media playback, file burning and data duplication.
- EXTENSIVE DISC COMPATIBILITY: CD DVD Burner designed to support multiple 120mm standard optical discs, covering CD-ROM, CD-R, CD±RW, DVD-ROM, DVD-R, DVD±RW, DVD-R DL and VCD-ROM. The widened inner space of the disc bay adapts to discs with thick printed labels. The optimized internal structural design effectively lowers the occurrence of disc skipping and burning failure, fully meeting your needs of data backup, movie watching, music collection and file storage.
- PORTABLE & DURABLE ALL-DAY DESIGN: CD/DVD player for laptop featuring compact size and lightweight body, this external optical reader-writer is equipped with brushed texture outer shell for enhanced wear resistance. Anti-slip rubber pads on the bottom ensure steady placement on various desktops. The reserved embedded cable slot can store the matched connecting cord neatly. Suitable for multiple scenarios including home entertainment, office file processing, campus study and outdoor business travel.
[Environment]::GetFolderPath("Desktop")
Then, to CD to the path, save the above command in a variable. Then, use PowerShell CD to change to the user’s desktop.
Here are the commands…
$Desktop = [Environment]::GetFolderPath("Desktop")
CD $Desktop
When I ran the two commands, my PowerShell console changed to my desktop…

Similarly, to change to the current user’s Documents folder, use the commands below.
Quick wins for a faster PC:
Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →Clear out junk files and repair common Windows errorsFree Scan →Scan for outdated or missing drivers - takes under a minuteDriver Scan →$Documents = [Environment]::GetFolderPath("MyDocuments")
Set-Location $Documents

Example 6: Use PowerShell CD (Set-Location) Command to Change to Program Files
To change to program files, first save the Program Files environment variable to a variable. Then, run the CD or Set-Location command and specify the variable as your path.
Here are the two commands…
$PF = $env:ProgramFiles CD $PF

Alternatively, if you want to change directory to the “Program Files(x86)” folder, use the commands below.
$PF86 = ${env:ProgramFiles(x86)}
CD $PF86

Example 7: Use Set-Location Command to Change Directory One Step Back from Current Directory
In the last example, I changed my current location to my Documents folder path – “C:\Users\VictorA\Documents”. In this example, I want to change directory one step backward to “C:\Users\VictorA”.
I can accomplish this task with the Push-Location command shown below…
Quick wins for a faster PC:
Clear out junk files and repair common Windows errorsFree Scan →Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →Push-Location ..
Here is the result…

On the opposite side of the coin, if my script requires me to cd forward to my previous path, I can use the Pop-Location command…

Example 8: Use PowerShell CD Command to Change Directory to a File’s Location
To change directory, to a file’s location, you can use the Get-ChildItem command to find the file’s location. Then, use Set-Location to the file’s path.
In this example, I want to find a file drivers.txt in drive D:\. Then, I’ll change my Powershell location to the path the folder is saved in.
Firstly, I’ll return the path the text file is saved with the command below.
(Get-ChildItem D:\ -Recurse | Where-Object {$_.Name -eq "drivers.txt"}).DirectoryName
The command shows that the drivers.txt is located in D:\report.
Also popular on Amazon
- Plug & Play Function with Simple Operation for All Users: No extra drivers or complicated installation steps are required for this external cd drive and external dvd drive. Just connect the cd burner for laptop to your computer’s USB 3.0 or Type-C port, and the device will be automatically recognized instantly. Designed with user-friendliness in mind, this dvd player for laptop and cd reader for laptop is suitable for both tech beginners and professional users. To ensure stable operation and sufficient power supply, we recommend direct connection to the computer’s original USB port instead of USB hubs or extension cables, bringing you a hassle-free using experience.
- Wide System & Device Compatibility for Universal Use: This external cd drive for laptop and cd burner for laptop delivers broad compatibility with multiple operating systems including Windows XP, Vista, 2000, ME, 7, 8.1, 10, 11, Linux and all macOS versions. It works perfectly with mainstream computer brands such as Apple, Dell, HP, Lenovo, ASUS, Samsung and more. This external cd/dvd drive for laptop is only compatible with laptops, desktop computers, all-in-one PCs and mini PCs. For better reading stability, desktop users are suggested to plug it into the rear USB port of the computer case. Please note that it is not compatible with TVs, tablets and in-car entertainment systems.
- High-Speed Transmission: Built with USB 3.0 and Type-C interfaces, high-performance external cd drive for laptop delivers fast data transfer speeds up to 5Gbps for quick disc reading and writing. This versatile external cd/dvd drive for laptop works with mainstream disc formats like DVD+R, DVD-R, CD-R, and CD-RW, boasting 8X max DVD read speed and 24X max CD read/write speed. It doubles as a functional cd burner for laptop to meet your daily disc operation needs. and an extra USB power cable is included to fix insufficient power issues for stable reading (power cable only for power supply, no data transfer). Note: It does not support DVD-RAM, Blu-ray discs and proprietary formats.
- Multifunctional & Stable Performance with Anti-Shock Technology: Equipped with intelligent error correction and anti-shock protection technology, this multifunctional external cd/dvd drive for laptop supports professional disc reading, writing and burning functions, serving as a practical cd burner, cd reader for laptop and dvd player for laptop. It effectively reduces reading errors and ensures smooth and stable disc operation during use. If the device fails to recognize discs or cannot read files, you can restart the computer or replace with standard CD-R/DVD-R discs for a retry. The thoughtful pop-up button and hidden built-in cable design greatly improve daily usability and portability.
- Slim Portable & Integrated Cable Design for Easy Carry: The lightweight external CD/DVD drive for laptop features a ultra-slim body and premium matte finish, paired with a practical built-in cable design for plug-and-go convenience. As a portable external cd drive and external dvd drive, it boasts durable construction and a compact size that fits effortlessly into laptop bags, taking up minimal space. This versatile cd reader for laptop and dvd player for laptop is an ideal daily companion for home entertainment, data backup, movie viewing, software installation, office work and business travel, allowing you to access and enjoy your CD and DVD collections anytime and anywhere.

But to change directory to this folder using the previous command without errors, I need to save the command in a variable.
$Path = (Get-ChildItem D:\ -Recurse | Where-Object {$_.Name -eq "drivers.txt"}).DirectoryName
Then, I’ll use the PowerShell CD command to change my location to the file’s saved directory…
$Path = (Get-ChildItem D:\ -Recurse | Where-Object {$_.Name -eq "drivers.txt"}).DirectoryName
CD $Path
There you go! My current PowerShell location has changed to the location of the file.
Do these 3 things before closing this tab:
1Fix the driver behind crashes, sound loss and screen glitches2Repair Windows errors before they cause bigger problems3Scan for outdated or missing drivers - takes under a minute
Frequently Asked Questions
The CD command is an alias of Set-Location. You can use CD or Set-Location to change your current PowerShell location to a specified location.
To change directory to drive C in PowerShell, run the Set-Location command and specify C as the path.
To get a file’s path in PowerShell, use the Get-ChildItem command, then call the FullName property.
To return a list of files in a directory and its subfolders, use the Get-ChildItem command with the -Recurse and -File parameters.
The Tool Desk
Outbyte PC Repair FREEClear out junk files and repair common Windows errorsFree Scan →Outbyte Driver Updater FREEFix the driver behind crashes, sound loss and screen glitchesFind Drivers →To get a file’s name in PowerShell, run the Get-ChildItem command and return the Name property of the Get-ChildItem command.
Conclusion
The PowerShell CD (or Set-Location) is a simple but PowerShell PowerShell command. You can use this command to change the current location in the PowerShell console.
Most importantly, you can use this command to change locations when running PowerShell scripts. This will make your scripts smarter and more intuitive.
I hope you found this guide helpful and easy to understand! If you did, click on “Yes” beside the “Was this page helpful” question below.
You may also express your thoughts and opinions by using the “Leave a Comment” form at the bottom of this page.
Finally, if you love learning PowerShell, you’ll love our PowerShell Explained articles.
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

