Drag and Drop to a Powershell script
- by Nathan Hartley
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
I then 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 Attempt 1
powershell.exe -noprofile -noexit -file c:\Test.ps1
I found that I can do this with a wrapper script...
Wrapper Script
#TestWrapper.ps1
& .\Test.ps1 -Paths $args
Shortcut Attempt 2
powershell.exe -noprofile -noexit -file c:\TestWrapper.ps1
Has anyone found a way to do this without the extra script?