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.
Standard Aliases for Set-Location: cd, chdir, sl
PowerShell Location is not the same as the Current Directory, used by Non-PowerShell utilities such as RoboCopy.
However Current Directory is available as a static environment variable:Read the System.Environment's CurrentDirectory property:
[environment]::CurrentDirectorySet the System.Environment's CurrentDirectory property:
[environment]::CurrentDirectory = "C:\music\mp3"The CMD shell's working directory does not automatically follow the current location of PowerShell for security reasons, older command-line applications may try to load certain DLLs from the current directory.
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 PowerShell Cmdlets:
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.