@ECHO OFF
SETLOCAL
cls
IF EXIST "%1" (
	Set InputFile=%1
	GOTO START
	)
ECHO Input File not found!
GOTO END
:START
ECHO Checking Powershell Version
:: Check for Powershell
IF NOT EXIST "%SYSTEMROOT%\system32\windowspowershell\v1.0\powershell.exe" (
	COLOR 0C
	ECHO "powershell.exe" not found!
	ECHO This script requires PowerShell V3.0 - install then re-run this script.
	COLOR
	pause
	EXIT
	)

"%SYSTEMROOT%\system32\windowspowershell\v1.0\powershell.exe" -Command "$host.Version.Major -gt 2" | find "True" >nul
IF %ERRORLEVEL% == 1 (
	COLOR 0C
	ECHO This script requires PowerShell version 3.0 or later!
	ECHO Your PowerShell version is:
	"%SYSTEMROOT%\system32\windowspowershell\v1.0\powershell.exe" $host.Version
	ECHO Please install then run this script again.
	COLOR
	pause
	EXIT
)

:OK
:: Get existing Powershell ExecutionPolicy
FOR /F "tokens=*" %%x in ('"%SYSTEMROOT%\system32\windowspowershell\v1.0\powershell.exe" Get-ExecutionPolicy') do (set ExecutionPolicy=%%x)
:: Set Bypass, in case we are running over a net share or UNC
IF NOT "%ExecutionPolicy%"=="Bypass" IF NOT "%ExecutionPolicy%"=="Unrestricted" (
	ECHO PS ExecutionPolicy is %ExecutionPolicy%, setting ExecutionPolicy to Bypass.
	"%SYSTEMROOT%\system32\windowspowershell\v1.0\powershell.exe" -Version 3 -Command Start-Process "$PSHOME\powershell.exe" -Verb RunAs -ArgumentList "'-Command Set-ExecutionPolicy Bypass'"
	)
GOTO LAUNCHSCRIPT
:LAUNCHSCRIPT
"%SYSTEMROOT%\system32\windowspowershell\v1.0\powershell.exe" -Version 3 -ExecutionPolicy ByPass -File "%~dp0%InputFile%"
GOTO END
:END
ENDLOCAL
