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.
CodePudding user response:
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 withpowershell.exe
, because it is the default, you must use it withpwsh
, whose default is-File
- Note: While
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.