0

Hey guys I'm writing a quick script, just before it enters the if block, I need to make sure the user is in the Documents folder.

if ($pwd -not $DocumentsPath)

thats the condition I used but I keep getting an error that states:

Unexpected token '-not' in expression or statement. At line:12 char:14

Unexpected token 'DocumentsPath' in expression or statement. At line:12 char:19

Musa
  • 553
  • 1
  • 7
  • 19

2 Answers2

2

You don't want the -not operator, that operator is for doing this like turning a $false in to a $true. What you want is "Not Equal" or -ne.

if ($pwd -ne $DocumentsPath)

Here is a list of the operators, to help you out in the future.

Scott Chamberlain
  • 124,994
  • 33
  • 282
  • 431
0

you must specify 'path' property

if($PWD.Path -ne $DocumentsPath) {...}

or

if(!$PWD.Path.Trim($DocumentsPath)) {...}
jojo
  • 36
  • 1