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.
Standard Aliases for Set-Location: cd, chdir, sl
In the bash shell, the command 'cd -' will jump to the previous working directory.
In PowerShell we can do the same with:
Set-Location ..
PowerShell Location is not the same as the global 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.
Set the current location to the C:\ drive in the FileSystem provider:
PS C:\> Set-Location C:
Change the current location to C:\Demo Files in the FileSystem provider, notice that unlike the CMD shell (CD), long filenames must be placed in double quotes:
PS C:\Work\> cd "\demo files"
PS C:\Work\Demo Files\>
Move back up the the work folder with ..
PS C:\Work\Demo Files\> cd ..
PS C:\Work\>
Or move up to the top level folder with \
PS C:\Work\Demo Files\> cd \
PS C:\>
Change the current location to the UNC path \\server64\projects in the FileSystem provider:
PS C:\> cd "\\server64\projects"
PS Microsoft.PowerShell.Core\FileSystem::\\server64\projects>
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
“Always get to the set or the location early, so that you can be all alone and draw your inspiration for the blocking and the setups in private and quiet” ~ Martin Scorsese
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.
How-To: Jump to the previous working directory.
Equivalent bash command: cd - Change Directory.