How to change drive and the directory in Windows PowerShell ?
This tutorial guides you how to change drive and the current directory in Windows PowerShell to different drive or directory.
Change directory in Windows PowerShell
There are many ways to change drive and directory in Windows PowerShell. The following are the different ways to do this.
Set-Location
Set-Location can be used to set current working location to a specified location as shown below.
Set-Location [[-Path] <String>] [-PassThru] [-UseTransaction] [<CommonParameters>]
For Example, Set-Location -Path E:/Work will set current working location to E:\Work
Windows PowerShell Copyright (C) 2014 Microsoft Corporation. All rights reserved. PS C:\Users\sneppets> Set-Location -Path E:/Work PS E:\Work>
To know the path of your current directory location, you can use the following command Get-Location
Windows PowerShell Copyright (C) 2014 Microsoft Corporation. All rights reserved. PS C:\> Get-Location Path ---- C:\
Note, built-in Windows PowerShell aliases like “cd“, “chdir” can be used instead of “Set-Location” which is explained above.
cd command
The following example shows how to use “cd” instead of “Set-Location” to change the current working directory.
PS C:\Users\sneppets> cd -Path E:/Work PS E:\Work>
chdir command
As said, “chdir” can also be used instead of “Set-Location” from PowerShell to change the directory as shown below
PS C:\Users\sneppets> chdir -Path E:/Work PS E:\Work>
Also See:
- Visual Studio Code change Terminal from powershell to cmd
- console.log() of an HTML element to know properties and events
- How to drop a mongodb database from mongo shell and command line?
- Import CSV using mongoimport command in MongoDB
- List all collections from mongo shell