Search code examples
powershellpowershell-core

$PWD vs. Get-Location in powershell or pwsh?


Powershell has $PWD and also Get-Location, both effectively returning the current "shell location" (as opposed to [System.Environment]::CurrentDirectory).

$PWDis documented as:

Contains a path object that represents the full path of the current directory location for the current PowerShell runspace.

And Get-Locationis documented as:

gets an object that represents the current directory, much like the print working directory (pwd) command.

Neither doc page mentions the other option.

So is there any difference in the value they produce? Possibly with multiple runspaces?


Solution

  • @Santiago answered this in the comments:

    $pwd is pretty much Get-Location with no parameters, both output $PSCmdlet.SessionState.Path.CurrentLocation but the cmdlet allows to get your location in different providers, psdrives and stacks