CmdID / PowerShell / Cmdlets / Get
Get-Location
Gets information about the current working location or a location stack. PowerShell reference
From the PowerShell reference
5 parameters
Aliases gl, pwd
What it does
Gets information about the current working location or a location stack. The Get-Location cmdlet gets an object that represents the current directory, much like the print working directory (pwd) command in Unix-like operating systems. When you move between PowerShell drives, PowerShell retains your location in each drive. You can use this cmdlet to find your location in each drive. You can use this cmdlet to get the current directory at run time and use it in functions and scripts, such as in a function that displays the current directory in the PowerShell prompt. You can also use this cmdlet to display the locations in a location stack. For more information, see the Notes and the descriptions of the Stack and StackName parameters.
Get-Location [-PSProvider <String[]>] [-PSDrive <String[]>] [-UseTransaction] [<CommonParameters>]Get-Location [-Stack] [-StackName <String[]>] [-UseTransaction] [<CommonParameters>]
Display your current drive location
PS C:\Windows> Get-LocationIdentifyDisplay your current location for different drives
PS C:> Set-Location C:\Windows
PS C:\Windows> Set-Location HKLM:\Software\Microsoft
PS HKLM:\Software\Microsoft> Set-Location "HKCU:\Control Panel\Input Method"
PS HKCU:\Control Panel\Input Method> Get-Location -PSDrive C
Path
----
C:\Windows
PS HKCU:\Control Panel\Input Method> Get-Location -PSDrive HKLM
Path
----
HKLM:\Software\Microsoft
PS HKCU:\Control Panel\Input Method> Set-Location C:
PS C:\Windows> Get-Location -PSProvider Registry
Path
----
HKCU:\Control Panel\Input MethodIdentifyGet locations using stacks
PS C:> Push-Location C:\Windows
PS C:\Windows>Push-Location System32
PS C:\Windows\System32>Push-Location WindowsPowerShell -StackName Stack2
C:\Windows\System32\WindowsPowerShell>Get-Location -Stack
Path
----
C:\Windows
C:\
C:\Windows\System32\WindowsPowerShell>Get-Location -StackName Stack2
Path
----
C:\Windows\System32IdentifyCustomize the PowerShell prompt
PS C:>
function prompt { 'PowerShell: ' + (Get-Location) + '> '}
PowerShell: C:>IdentifyIts page in the reference: Get-Location.
Parameters
-PSDriveGets the current location in the specified PowerShell drive.
For instance, if you are in the Cert: drive, you can use this parameter to find your current location in the C: drive.-PSProviderGets the current location in the drive supported by the specified PowerShell provider. If the specified provider supports more than one drive, this cmdlet returns the location on the most recently accessed drive.
For example, if you are in the C: drive, you can use this parameter to find your current location in the drives of the PowerShell Registry provider.-StackIndicates that this cmdlet displays the locations added to the current location stack. You can add locations to stacks by using the Push-Location cmdlet.
To display the locations in a different location stack, use the StackName parameter. For information about location stacks, see the Notes.-StackNameSpecifies, as a string array, the named location stacks. Enter one or more location stack names.
To display the locations in the current location stack, use the Stack parameter. To make a location stack the current location stack, use the Set-Location cmdlet.
This cmdlet cannot display the locations in the unnamed default stack unless it is the current stack.-UseTransactionIncludes the command in the active transaction. This parameter is valid only when a transaction is in progress. For more information, see about_Transactions.