Please feel free to provide feedback or file bugs here.

[BUG] Drag and drop to scripts shortcuts split paths containing spaces

Drag and dropping any file to a script shortcut split this path before passing the splitted strings as multiple parameters. Here's my detailed Issue Report :

Steps to reproduce
------------------

1 - Get any script, for example :
[samplescript.psd1] :
```
param([string]$path)
Write-Host($path)
pause
```
or a simpler one-line sample: ```Write-Host($args);pause```

2 - Create a shortcut that runs the script :
[Shortcut Target ] : ```PowerShell "path\to\our\samplescript.psd1"```

3- Drag and drop a file containing spaces in its name to the shortcut
[sample file ] : ```C:\Some file with spaces.txt```

Expected behavior
-----------------

Drag and dropping the file should pass its path to the script as a parameter, (as it does correctly with batch scripts, executables, and other files that accept drag and drop [and shortcuts to these]),
and the script should then open a PowerShell window displaying "C:\Some file with spaces.txt"

Actual behavior
---------------

The file path is split into multiple parameters before being passed to the PowerShell script, which displays "C:\Some", instead of "C:\Some file with spaces.txt"

Workaround
---------------

Well, that isn't brilliant since I'm since starting to have a lot of these, but since this bug is only with powershell I simply create a .bat file which passes the argument to a PowerShell file. Instead of drag and dropping to the script shortcut; I drop it on the bat file [or a shortcut to it] to pass the path to the bat file, which then pass the path to the PowerShell script. Like this :
[dragdrop_for_samplescript.bat]
```start PowerShell -file "path\to\our\samplescript.psd1" %1```

Environment data
----------------

```
> $PSVersionTable

Name Value
---- -----
PSVersion 5.1.16257.1
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.16257.1
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
```

3 votes
Sign in
Check!
(thinking…)
Reset
or sign in with
  • facebook
  • google
    Password icon
    Signed in as (Sign out)

    We’ll send you updates on this idea

    Amine I. shared this idea  ·   ·  Flag idea as inappropriate…  ·  Admin →

    2 comments

    Sign in
    Check!
    (thinking…)
    Reset
    or sign in with
    • facebook
    • google
      Password icon
      Signed in as (Sign out)
      Submitting...
      • James Chaldecott commented  ·   ·  Flag as inappropriate

        It definitely happens for me without a Param() block, although theon-liner doesn't make it obvious.

        Try this instead:

        ````
        foreach ($arg in $args)
        {
        Write-Host($arg)
        }

        pause
        ````

        Dropping several items on a shortcut to that script yields one line per file *only* if they have no spaces in the filenames. If there are spaces in the filenames you can see that each file with a space has been incorrectly split into multiple array items.

        PowerShell 5.0 on Window 7.

        >$PSVersionTable

        Name Value
        ---- -----
        PSVersion 5.0.10586.117
        PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
        BuildVersion 10.0.10586.117
        CLRVersion 4.0.30319.42000
        WSManStackVersion 3.0
        PSRemotingProtocolVersion 2.3
        SerializationVersion 1.1.0.1

      • Amine I. commented  ·   ·  Flag as inappropriate

        UPDATE : The bug seems to only affects the scripts with a Param( ) block :
        the one-line-script provided (Write-Host($args);pause) is in fact not affected

      Feedback and Knowledge Base