@echo off REM Alan dot Kaplan at VA dot Gov 2/11/14 REM This batch file will allow you to execute a PowerShell Script by drag and drop of a script REM shortcut to a PowerShell script. You will be prompted for authentication choice. Setlocal set target=%1 IF /I NOT %~x1.==.lnk. GOTO RunPS rem to get the path from a shortcut, create a vbscript in %temp% rem See http://stackoverflow.com/questions/7081847/porting-an-xp-batch-file-to-win7 echo set WshShell = WScript.CreateObject("WScript.Shell") > %temp%\DecodeShortCut.vbs echo set oLnk = WshShell.CreateShortcut(WScript.Arguments(0)) >> %temp%\DecodeShortCut.vbs echo wscript.echo oLnk.TargetPath >> %temp%\DecodeShortCut.vbs rem run the script and get the target path set vbscript=cscript //nologo "%temp%\DecodeShortCut.vbs" For /f "delims=" %%T in ( ' %vbscript% ""%1"" ' ) do set target=%%T del %temp%\DecodeShortCut.vbs :RunPS Echo To run %target%, echo type letter for authentication method (no RETURN). echo After 10 seconds, current credentials will be selected CHOICE /C SACX /M "(S)martCard, (C)urrent or (A)lternate credentials - e(X)it. " /T 10 /d C if ErrorLevel == 4 Exit if ErrorLevel == 3 powershell -noexit "& "%target%" if ErrorLevel == 2 goto :GetName if ErrorLevel == 1 runas /smartcred "powershell -noexit -file %1" Goto End :GetName set /p RunAsName=Enter Admin Username, ex: %USERDOMAIN%\%USERNAME%: runas /user:%RunAsName% "powershell -noexit -file %1" & Goto :end :end EndLocal pause