Does Powershell support drag and drop?

I have this CMD Batch, I hope I can use it PowerShell like this :

:parse
IF “%~1”=="" GOTO endparse
call :handle_one_file %1
SHIFT
GOTO parse
:endparse

:handle_one_file
TITLE “%~1”
echo do something about “%~1”

 

Dragging a file to a powershell window will paste the path. For instance, if you wanted to get file details with Get-Item, you can type Get-Item<space> and then drag a file into the Powershell window:

PS C:\Users\rasim> Get-Item C:\Scripts\test.csv


    Directory: C:\Scripts


Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
-a----          4/3/2020  10:06 AM          10346 test.csv

so, there no way to do drag and drop using power shell?

sorry another question, is possible to use “%~1” parameter from CMD and using it on PowerShell?

and thank for the reply

Not really sure exactly what you mean by ‘drag and drop’ here. Explain what you are dragging and where you are dropping it to execute what? You can drag files into a Powershell window to get a path.

Again, not really sure what you are asking. Explain exactly what you want to do and expected results. Provide examples.

something like this

:parse
IF "%~1"=="" GOTO endparse
call :handle_one_file %1
SHIFT
GOTO parse
:endparse

:handle_one_file
TITLE "%~1"
PowerShell -ExecutionPolicy Bypass -C DOSOMETHING ABOUT "%~1"

edit : somehow the reply text always show as html code, i dont know how to fix it, sorry

i hate this, the text always show as HTML code, when i did edit this, the reply is gone,

anyway the example code:

:parse
IF “%~1”=="" GOTO endparse
call :handle_one_file %1
SHIFT
GOTO parse
:endparse

:handle_one_file
TITLE “%~1”
PowerShell -ExecutionPolicy Bypass -C “%~1”

Yes, you didn’t read the guide. If you had, you would know why it happens and how to fix it.

Yes, that should be possible assuming you are dragging a PS1 file to the bat. Would recommend the full path to Powershell. Also would say there isn’t really a need for a batch file at all as you are dragging a PS1 to open CMD to open Powershell. CMD\DOS is considered deprecated and in Windows 10 the CMD prompt is actually Powershell, hence you would be opening Powershell to open Powershell to execute a PS1.

https://support.microsoft.com/en-us/windows/powershell-is-replacing-command-prompt-fdb690cf-876c-d866-2124-21b6fb29a45f#:~:text=To%20create%20the%20best%20command,the%20whitespace%20in%20File%20Explorer.

Drag and drop is a wonderful facility that most of us will use every day without even thinking about it.

To achieve our objective, we need to make use of two events, DragOver, and DragDrop.

DragOver occurs when the mouse is over the control on which we wish to ‘drop’ our object. We’ll typically just use this for changing our pointer to show a move or copy operation is in operation.

DragDrop occurs once the actual operation is finished. That is, the object has been dragged into the form and over the control, and the mouse button released.

To implement this in our application, carry out the following:

Create a form
Create a Textbox on the form
Set the following properties for the Textbox
Name : txtDragandDrop
Label : Contents dragged:
AllowDrop : true

We now define the events that will be processed, and their handlers.

DragDrop : txtDragandDrop_DragDrop
DragOver : txtDragandDrop_DragOver

If you are developing this application in PowerShell Studio, you will need to first export the code, either to a standalone EXE, or .PS1 file.

Run the application from either of the above.
Drag a file of you choice from explorer to the textbox.

I hope this information will be helpful!

Ben Martin