2

While implementing the suggestions in the topic Drag and Drop to a Powershell script we discovered that PowerShell consolidates multiple spaces into one. This is blocking us from dragging and dropping files through Windows Explorer into .bat/.ps1 constructs with multiple spaces.

This can easily be verified by the following command:

powershell -command "& echo {"a  a"}"

This will result in:

a a

whereas the following result is expected:

a a

How can this be achieved?

Please note that your provided solution must fit into the Windows Explorer drag-and-drop .bat -> .ps1 flow. Currently in the .bat file we have: powershell.exe -Command "& '%PSScript%' '%*'" which obviously results in PowerShell stripping the duplicate spaces.

Community
  • 1
  • 1
Carl in 't Veld
  • 1,363
  • 2
  • 14
  • 29
  • Possible duplicate of [Powershell - escaping string passed to child process](http://stackoverflow.com/questions/34276662/powershell-escaping-string-passed-to-child-process) – user4003407 Feb 09 '17 at 16:34

4 Answers4

1

try this

powershell -command "& echo 'a  a'"
Esperento57
  • 16,521
  • 3
  • 39
  • 45
0

Please Check if below solves your problem.

"Replace 10 with number of spaces you want."

powershell -command '& echo {"a"' ''.padleft(10, ' ') '"a"}'

output:

a            a
Ajay Pawar
  • 179
  • 6
0

works for me with a simple :

write-host a ("    ") a
0

Use ` to escape spaces like:

Write-Host "a` ` ` a"

Output:

a   a
scruel
  • 426
  • 6
  • 14