Thanks to visit codestin.com
Credit goes to www.tutorialspoint.com

Use the Set-Location Command in PowerShell



Set-Location command in PowerShell is used to set the location of the drive from the current directory. The drive could be the local drive, folder path, shared path, registry, or any environmental variable.

This command is very useful while writing the script because many times we need multiple files from the same folder and each time we need to mention the full path. This command allows us to set the path at the beginning of the script and then we can directly browse the path from the current directly.

Example 1 − The below command sets the location from the C: to C:\Temp

PS C:\> Set-Location C:\Temp\ -PassThru
Path
----
C:\Temp

Example 2 − The below command sets the location to the registry path from the current path.

PS C:\> Set-Location HKLM:\
PS HKLM:\>

Example 3 − The below command sets the location to the PSDrive from the current path.

PS C:\> Set-Location Env:\
PS Env:\>
PS C:\> Set-Location Cert:\
PS Cert:\>
Updated on: 2020-11-02T11:07:34+05:30

2K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements