通过拖放文件或文件夹来运行 powershell 脚本

bur*_*tek 4 windows-7 powershell shell-script drag-and-drop

有没有办法通过在上面拖放文件来运行 powershell 脚本(就像将文件拖放到 .exe 文件一样)?能够对文件夹做同样的事情也很好......

zda*_*dan 5

创建 Windows 资源管理器快捷方式(在资源管理器中右键单击 -> 新建 -> 快捷方式)。然后右键单击您的快捷方式并打开“属性”对话框。在目标字段中输入如下内容:

C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -noexit -noprofile -file C:\yourscriptdirectory\yourscript.ps1
Run Code Online (Sandbox Code Playgroud)

是否需要-noexit-noprofile选项由您决定,请查看帮助来决定。

现在,当您将文件(或文件夹)拖放到此快捷方式上时,资源管理器会神奇地将其作为第一个参数传递给您的脚本。