As I am sure you probably know, PowerShell allows you to switch between file system drives by simply entering the drive letter followed by a colon. For example, you would enter C: to switch to the C: drive.
The cd command, also known as chdir (change directory), is a command-line shell command used to change the current working directory in various operating systems. It can be used in shell scripts and batch files.
Use " " Double Quotes to Deal With Spaces in the Path While Changing the Current Directory in PowerShell. The cd command changes the current directory in PowerShell. If the path contains spaces, you will get an error when you don't put the path in double quotes " " .
Unlike the CMD.EXE CHDIR
or CD
command, the PowerShell Set-Location
cmdlet will change drive and directory, both. Get-Help Set-Location -Full
will get you more detailed information on Set-Location
, but the basic usage would be
PS C:\> Set-Location -Path Q:\MyDir
PS Q:\MyDir>
By default in PowerShell, CD
and CHDIR
are alias for Set-Location
.
(Asad reminded me in the comments that if the path contains spaces, it must be enclosed in quotes.)
To go directly to that folder, you can use the Set-Location
cmdlet or cd
alias:
Set-Location "Q:\My Test Folder"
Multiple posted answer here, but probably this can help who is newly using PowerShell
SO if any space is there in your directory path do not forgot to add double inverted commas "".
You can simply type Q:
and that should solve your problem.
Set-Location -Path 'Q:\MyDir'
In PowerShell cd
= Set-Location
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With