learn windows

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:

References

Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments