4

(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

Andrew
  • 55
  • 1
  • 2
  • 4
  • you need to address the desired property of the object stored in that $Var. in this case, look at `$PWD.Path`. also, take a look at the other properties that are available via `$PWD | Get-Member` - there are other items there that may be useful. [*grin*] – Lee_Dailey Jul 05 '21 at 08:48

1 Answers1

5

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
SimonS
  • 8,924
  • 5
  • 28
  • 48