How to use the Set-Location command in PowerShell?

PowerShellMicrosoft TechnologiesSoftware & Coding

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:\>
raja
Published on 02-Nov-2020 11:07:17
Advertisements