I thought I had an answer to this, but the more I play with it, the more I see it as a design flaw of Powershell.
I would like to drag and drop (or use the Send-To mechanism) to pass multiple files and/or folders as a array to a Powershell script.
Test Script
#Test.ps1
param ( [string[]] $Paths, [string] $ExampleParameter )
"Paths"
$Paths
"args"
$args
Attempt #1
I created a shortcut with the following command line and dragged some files on to it. The files come across as individual parameters which first match the script parameters positionally, with the remainder being placed in the $args array.
Shortcut for Attempt #1
powershell.exe -noprofile -noexit -file c:\Test.ps1
Wrapper Script
I found that I can do this with a wrapper script...
#TestWrapper.ps1
& .\Test.ps1 -Paths $args
Shortcut for Wrapper Script
powershell.exe -noprofile -noexit -file c:\TestWrapper.ps1
Batch File Wrapper Script
And it works through a batch file wrapper script...
REM TestWrapper.bat
SET args='%1'
:More
SHIFT
IF '%1' == '' GOTO Done
SET args=%args%,'%1'
GOTO More
:Done
Powershell.exe -noprofile -noexit -command "& {c:\test.ps1 %args%}"
Attempted Answers
Keith Hill made the excellent suggestion to use the following shortcut command line, however it did not pass the arguments correctly. Paths with spaces were split apart when they arrived at the Test.ps1 script.
powershell.exe -noprofile -noexit -command "& {c:\test1.ps1 $args}"
Has anyone found a way to do this without the extra script?