2

First off I know the obvious answer is to not use a directory with a space in it, but at this point it is just bothering me that I do not know how to.

$f = "$env:userprofile/desktop/art folder/art.png"

iwr DropBoxUrl -o $f 

this works fine in a powershell console but from the runbox it shows the following error:

At line:1 char:22
+ $s = $env:USERPROFILE\desktop\art folder\art.png; iwr https://www.dropb ...
+                      ~~~~~~~~~~~~
Unexpected token '\desktop\art' in expression or statement.
I am Jakoby
  • 577
  • 4
  • 19

1 Answers1

1

Assuming you mean the Windows Run dialog (WinKey-R):

  • Its use requires calling the PowerShell CLI (powershell.exe for Windows PowerShell, pwsh for PowerShell (Core) 7+)

  • Since you're trying to execute commands (rather than a script file (.ps1)), use of the -Command (-c) parameter is required.

    • Note: While -Command (-c) can be omitted with powershell.exe, because it is the default, you must use it with pwsh, whose default is -File
  • Any " characters that are to become part of the PowerShell command(s) to execute must be escaped as \".

    • If you don't escape them, they are removed during the initial command-line parsing, resulting in the error you saw.

    • See this answer for an explanation.

Therefore, using powershell.exe:

powershell.exe -noexit -c "$f = \"$env:userprofile/desktop/art folder/art.png\"; iwr DropBoxUrl -o $f"

Note: I've added the -noexit switch so as to keep the session open, which allows you to see the results.

mklement0
  • 382,024
  • 64
  • 607
  • 775