0

I tried :

Join-Path [Environment]::GetFolderPath("Desktop") "\test\test.txt"

but got error Join-Path : A positional parameter cannot be found that accepts argument

user310291
  • 36,946
  • 82
  • 271
  • 487
  • 1
    `Join-Path $([Environment]::GetFolderPath("Desktop")) "\test\test.txt"` – Olaf Aug 10 '22 at 21:27
  • 3
    What Olaf said, except you don't even need the `$`, so just `Join-Path ([Environment]::GetFolderPath("Desktop")) "\test\test.txt"` works. You just need to put parenthesis around it so PowerShell knows to evaluate that first, and then do the `Join-Path` part. – TheMadTechnician Aug 10 '22 at 22:06
  • @TheMadTechnician thanks but why do I need to use ( ) ? Why PowerShell doesn't know how to evaluate that first – user310291 Aug 10 '22 at 22:18
  • It doesn't know to evaluate that first because there is nothing telling it to evaluate that first, that is why you have to use the ( ). – TheMadTechnician Aug 10 '22 at 23:17
  • 1
    This is because PowerShell has two distinct parsing modes. When it sees a command like `Join-Path`, it enters _argument mode_, which is very limited but simplifies easy tasks, e. g. passing unquoted string literals. For more complex arguments, you need to force it into _expression mode_, by using parentheses. – zett42 Aug 10 '22 at 23:43

0 Answers0