Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

$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?

like image 651
Martin Ba Avatar asked Oct 15 '25 23:10

Martin Ba


1 Answers

@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

like image 122
Martin Ba Avatar answered Oct 17 '25 18:10

Martin Ba



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!