Drag and Drop to a Powershell script
Posted
by Nathan Hartley
on Stack Overflow
See other posts from Stack Overflow
or by Nathan Hartley
Published on 2010-05-12T14:48:47Z
Indexed on
2010/05/12
15:24 UTC
Read the original article
Hit count: 430
powershell
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?
© Stack Overflow or respective owner