Is there a way to interact with powershell the same way as with command prompt?

With command with the cmd/bat files you can drag-n-drop file/folder over the script itself, and it will be evaluated as parameter.


@echo off
echo %1

The code will result in this, when you drop the file on script file

enter image description here

  • 1
    Possibly more clear question title: Start a PowerShell script by dragging files onto its icon? – I say Reinstate Monica Aug 24 '18 at 15:57
  • 2
    Possible duplicate of Running powershell scripts by drag-n-drop file or folder on it – LotPings Aug 24 '18 at 16:06
  • @TwistyImpersonator yea, this is better. Changed – Bakudan Aug 25 '18 at 20:06
  • @LotPings although this is a solution, the idea was if it is possible to make it without a mediaor - the shortcut in this case. – Bakudan Aug 25 '18 at 20:08
  • @LotPings we did this back in 2008 at my last job. You have to create some registry entries for the drop handler. I am pretty sure I have a copy of this on an old flash drive. Hopefully I can find it – Squashman Feb 26 '19 at 9:45

enter image description here

.ps1 are associated with notepad by design, to prevent inadvertent runs like you can with .bat, .cmd. It's a risk management thing. You can change that via the normal file explorer way, but don't.

If you are saying, you want drag and drop .bat, .cmd on to a PS host and expect it to run, then no, PS will not do this. It is not designed for that. You have to call cmd.exe from PS to run .bat, .cmd files.

You can also add the PS shortcut to your SendTo folder. right click your script, select Sendto, and select the PS shortcut you created, or you can hack the registry to add PS the File Explorer main right click menu and avoid the SendTo step, but that is far more work.

Either way, this is not out of the box, and you are going to have to create something to pop the ps exe to run a script auto-magically once you drop or send something to it.

You can natively, drag and drop a file natively PS console or ISE script pane as long as they are started using the current user identity. In the console then just hit enter, in the ISE hit F5 (or click the big green button).

enter image description here

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.