How to Get Current Path in Powershell into a Variable

How to Get Current Path in Powershell into a Variable

(I don't speak English. Hope you understand.)

Hi, I have a powershell script(.ps1) and it needs to work with the current path(e.g. "C:\Users\user\Desktop"). I don't know how to set it into a variable. I know the variable $PWD, but it is:

Path          
----          
C:\Users\user\Desktop

and I need it without 'Path ----'.

Thank you for the answers, Andrew

1

1 Answer

Here are some ways to do that. basically you just need to expand the path property.

PS C:\WINDOWS\system32> $PWD

Path
----
C:\WINDOWS\system32

PS C:\WINDOWS\system32> $PWD.Path
C:\WINDOWS\system32
PS C:\WINDOWS\system32> $PWD | select -Expand Path
C:\WINDOWS\system32
PS C:\WINDOWS\system32> (get-location).path
C:\WINDOWS\system32
1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Alexander Ross
Author

Alexander Ross

Alexander Ross has covered the video game industry for a decade, writing deep dives on game design, esports tournaments, VR developments, and gaming culture.