Get and display the current location.
Syntax Get-Location [-psDrive string] [-psProvider string] [-UseTransaction] [CommonParameters] Get-Location [-stack] [-stackName string] [-UseTransaction] [CommonParameters] Key -psDrive Get the current location in the specified PowerShell drive. For example, if you are in the Certificate: drive, find the current location in the C: drive. -psProvider Get the current location in the drive supported by the specified PowerShell provider. For example, if you are in the C: drive, find the current location in the Registry via the PowerShell Registry provider. If the specified provider supports more than one drive, Get-Location will returns the location on the most recently accessed drive. -stack Display locations in the default path stack To add paths to the default stack, use Push-Location. -stackName Display locations in the specified path stacks. To create path stacks, use Push-Location. -UseTransaction Include the command in the active transaction.
Standard Aliases for Get-Location: pwd, gl
Get-Location gets an object that represents the current directory within PowerShell, like the unix pwd (print working directory) command.
When you move between PowerShell drives, PowerShell will retain your location in each drive. Get-Location can be used to find your location in each drive.
The current path does not necessarily point to a File System location. If you change location to the registry, then Get-Location will return the current registry key:
PS> cd hkcu:\
To return the current File System location, regardless of the current provider:
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:
Set the System.Environment's static CurrentDirectory property:
[environment]::CurrentDirectory = "C:\music\mp3"
Display the current working location:
PS C:\> get-location
Display the current directory for drive C: even when working in the registry:
PS C:\> set-location C:\Windows
PS C:\> set-location HKLM:\Software\Microsoft
PS C:\> get-location -psdrive c
#Home! Home! sweet, sweet Home! There's no place like Home! # ~ John Howard Payne
Related PowerShell Cmdlets:
Pop-Location - Change the current working location to the last pushed onto the stack (popd).
Push-Location - Push a location to the stack (pushd).
Set-Location - Set the current working location (cd).
Get-PSDrive - Get drive information (DriveInfo).
Equivalent bash command: pwd - Print Working Directory.