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. CommonParameters: -Verbose, -Debug, -ErrorAction, -ErrorVariable, -WarningAction, -WarningVariable, -OutBuffer -OutVariable.
Standard Aliases for Get-Location: pwd, gl
Get-Location gets an object that represents the current directory, much like the 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.
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
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)
Equivalent bash command: pwd - Print Working Directory