Running powershell scripts by drag-n-drop file or folder on it
Create a Windows Explorer shortcut (In Explorer right click -> new -> shortcut). Then right-click on your shortcut and open the Properties dialog box. In the Target field enter something like this:
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -noexit -noprofile -file C:\yourscriptdirectory\yourscript.ps1
Whether you need the -noexit
or -noprofile
options is up to you, take a look at the help to decide.
Now when you drop a file (or folder) onto this shortcut, explorer will magically pass it as the first argument to your script.