Set the current PowerShell working location.
Syntax
Set-Location [[-path] string] [-passThru]
[-UseTransaction] [CommonParameters]
Set-Location [-literalPath] string] [-passThru]
[-UseTransaction] [CommonParameters]
Set-Location [-stackName string] [-passThru]
[-UseTransaction] [CommonParameters]
Key
-path string
The path to a new working location.
-literalPath string
Like Path above, only the value is used exactly as typed.
No characters are interpreted as wildcards. If the path includes any
escape characters then enclose the path in single quotation marks.
-stackName
The stack to which the location is being set.
-passThru
Pass the object created by this cmdlet through the pipeline.
-UseTransaction
Include the command in the active transaction.
CommonParameters:
-Verbose, -Debug, -ErrorAction, -ErrorVariable, -WarningAction, -WarningVariable,
-OutBuffer -OutVariable.
PowerShell Location is not the same as the process Current Directory. This means that non PowerShell utilities such as RoboCopy will default to the old style Current Directory, which is held as a static environment variable [environment]::CurrentDirectory
Read the System.Environment's static CurrentDirectory property:
[environment]::CurrentDirectory
Set the System.Environment's static CurrentDirectory property:
[environment]::CurrentDirectory = "C:\music\mp3"
Examples
Set the current location to HKLM in the registry provider:
PS C:\>set-location HKLM:
Set the current location to the environment variable provider:
PS C:\>set-location env: -passthru
Set the current location to the C:\ drive in the FileSystem provider:
PS C:\>set-location C:
“The three most important factors in buying a home are, location, location, location!”
Related:
Get-Location - Get and display the current location
Pop-Location - Set the current working location (from the stack)
Push-Location - Push a location to the stack
Equivalent bash command: cd - Change Directory
© Copyright SS64.com 1999-2013
Some rights reserved