My PowerShell prompt's currently pointed to my C drive (PS C:\>). How do I change directory to a folder on my Q (PS Q:\>) drive?
The folder name on my Q drive is "My Test Folder".
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.)
-Path parameter. Why? Is it always the case?Set-Location cmdlet, since the most common use will be to use it like the old CD command, it makes sense for the "default" interpretation of an omitted parameter name to be to assume that it's the -Path parameter, and that's how the cmdlet was written. Other cmdlets may not default the same way. See the help information (linked in the answer) for a more detailed discussion.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 "".
Set-Location 'C:\Path With Spaces'double inverted commas 🤦♂️You can simply type Q: and that should solve your problem.
Set-Location -Path 'Q:\MyDir'
In PowerShell cd = Set-Location
cd alias, neither have you.I don't know why everyone talks about Set-Location and the fact that cd does not change drive and directory, in fact it actually does it (in powershell, not cmd), you just need to put quotes (single or double) around if there are spaces in folder name(s), also you can just type drive letter if you just want to go to its root:
Edit: now I started editing my PowerShell scripts with a "real" IDE I understood why everyone talks about Set-Location, cd is just an alias to it:
If your Folder inside a Drive contains spaces In Power Shell you can Simply Type the command then drive name and folder name within Single Quotes(''):
Set-Location -Path 'E:\FOLDER NAME'
cd -Path Q:/Push-LocationandPop-Location