0

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.

Edit:

@echo off
cls
echo %1
pause

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

enter image description here

5
  • 1
    Possibly more clear question title: Start a PowerShell script by dragging files onto its icon? Aug 24, 2018 at 15:57
  • 2
    Possible duplicate of Running powershell scripts by drag-n-drop file or folder on it
    – LotPings
    Aug 24, 2018 at 16:06
  • @TwistyImpersonator yea, this is better. Changed
    – Bakudan
    Aug 25, 2018 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, 2018 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, 2019 at 9:45

1 Answer 1

0

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .