In Powershell, you can run automation scripts from specific folders or perform specific tasks in different file locations. However, it opens in the user account folder by default, and the Elevated version of it opens in the System32 folder.
So, to use the full extent of PowerShell, you will need to change directories and be able to navigate them. To do so, you can either use the built-in cmdlet made to navigate your current working directory (CWD) or its aliases like cd, sl, or chdir.
Change Directory Using Absolute Path
You can easily change your current working directory in PowerShell by using the Set-location cmdlet. Its syntax is Set-location “absolute file path”
.
The “absolute file path” refers to the full file location of the particular folder you’re trying to navigate towards. For instance, the Set-location “C:\Windows\Temp”
will change your CWD to the Temp folder.
If you don’t know how to get the full file path of a particular folder, you can right-click that specific folder in File Explorer and select Copy as path. Then, you can simply put the Set-location cmdlet and paste your copied file path into Powershell.
Additionally, the double quotation marks enclosing the “absolute file path” isn’t mandatory. It is only necessary to enclose them within double quotation marks if your file path contains spaces. For example, Set-location “D:\Adobe Photoshop\config files”
.
Change Directory Using Relative Path
Changing the directory using relative file path also uses the same Set-location cmdlet, but you won’t need to enter the full file path of a folder. In a nutshell, it’s simply changing to a subfolder from a folder you’re already in.
For instance, your current working directory is C:\Windows
and you want to get to the C:\Windows\Temp folder
. In such cases, instead of using the above method, you can use the Set-location cmdlet with the relative file path. The command should look like this: Set-location Temp
Furthermore, you can keep adding more subfolders in the relative file path to navigate to the subfolder’s subfolder, and so on. For example, Set-location Temp\Crashpad\reports
. (Make sure to add quotations if they contain spaces.)
Additionally, if you don’t remember the name of the subfolder you want to navigate to, you can use the dir
cmdlet alias to view all the files and folders present in your CWD.
Change to Parent Folder in PowerShell
Using the Set-location cmdlet, you can also go back to the parent folder of a directory you’re currently in. For example, if you’re in C:\Windows\Temp
, and you want to navigate back to C:\Windows
, you can use the Set-location ..
command to directly go back to C:\Windows
.
Also, if you want to jump back to the root folder of your current working directory, you can use the Set-location \
command. For example, if your CWD is C:\Windows\Temp\Crashpad\reports
, this command will directly take you to C:
.
Set-location Aliases
You can also use Set-location aliases instead of the full Set-location cmdlet. A cmdlet alias is basically a shortened version of a cmdlet that performs the same function as the original cmdlet. The Set-location cmdlet has three aliases—cd
, sl
, and chdir
.
You can use any of the three aliases instead of the actual cmdlet. The syntax for using the three aliases in any scenario is the same as Set-location.
However, the cd
alias does differ slightly compared to Set-location and its other aliases. When using the cd alias, you won’t need spaces when navigating back to the parent or root folder. For example, cd..
and cd\
will work perfectly fine, but Set location..
And Set-location\
won’t work.
Lastly, you can also jump directly to a particular directory in PowerShell from File Explorer. All you need to do is to navigate to that folder in File Explorer and enter powershell
in the address bar.