@ECHO Off
if /I "%~1"=="/configure" (
    powershell.exe -NoProfile -ExecutionPolicy Bypass -File "%~dp0MAR\Initialize-MarConfiguration.ps1" -Configure
    exit /b %errorlevel%
)

powershell.exe -NoProfile -ExecutionPolicy Bypass -File "%~dp0MAR\Initialize-MarConfiguration.ps1"
if %errorlevel% neq 0 (
    set "MAR_CONFIGURATION_RESULT=%errorlevel%"
    echo MAR deployment configuration could not be applied. Stopping script execution...
    pause
    exit /b %MAR_CONFIGURATION_RESULT%
)
powershell.exe -NoProfile -ExecutionPolicy Bypass -File "%~dp0MAR\Test-MarWindowsBuild.ps1"
if %errorlevel% neq 0 (
    set "MAR_BUILD_RESULT=%errorlevel%"
    echo Windows does not meet the configured minimum build. Stopping script execution...
    pause
    exit /b %MAR_BUILD_RESULT%
)
powershell.exe -NoProfile -ExecutionPolicy Bypass -File "%~dp0MAR\Test-MarOa3ToolVersion.ps1"
if %errorlevel% neq 0 (
    set "MAR_OA3TOOL_RESULT=%errorlevel%"
    echo OA3Tool does not meet the configured minimum version. Stopping script execution...
    pause
    exit /b %MAR_OA3TOOL_RESULT%
)
powershell.exe -executionpolicy bypass -file %~dp0MAR\secure_tpm.ps1
if %errorlevel% neq 0 (
    set "MAR_PREREQUISITE_RESULT=%errorlevel%"
    echo TPM or Secure Boot requirements are not met. Stopping script execution...
    pause
    exit /b %MAR_PREREQUISITE_RESULT%
)
powershell.exe -executionpolicy bypass -file %~dp0MAR\Windows_11_Compatibility.ps1

:: If the exit code from PowerShell is 1 (or anything other than 0), stop the batch file
if %errorlevel% neq 0 (
    echo Machine is not Windows 11 Compatible. Stopping script execution...
    pause
    exit /b
)

:: The rest of your batch script goes here...
echo Machine is compatible! Continuing...

:Begin
Color 70
for /f "tokens=1,* delims=," %%I in ('powershell -Command "& { (Get-CimInstance Win32_OperatingSystem).Caption }"') do set "OS=%%I"
Echo %OS%
	
If /I "%OS%" == "Microsoft Windows 11 Pro" (
	ECHO.
	ECHO.
	ECHO.
	ECHO.
	ECHO.
	ECHO.
	ECHO.%OS% Detected, Hit Any Key to Advance to The Windows 11 Pro Menu
	Pause
	CLS
	GOTO :Win112
)
	
If /I "%OS%" == "Microsoft Windows 11 Home" (
	ECHO.
	ECHO.
	ECHO.
	ECHO.
	ECHO.
	ECHO.
	ECHO.%OS% Detected, Instaling Windows 11 Home DPK in. . . 
	TIMEOUT 5
	CLS
	Start "MAR Home 11" /wait %~dp0MAR\Home11\Script\RunMe.bat
)
	
If /I "%OS%" == " " (
	ECHO.
	ECHO.
	ECHO.
	ECHO.
	ECHO.
	ECHO.
    ECHO.No OS Detected, Press Any Key to Advance to Main Menu
	Pause
	CLS
	GOTO :Select
)	

:Select
ECHO.
ECHO.
ECHO.
ECHO.
ECHO.
ECHO.
ECHO.
ECHO.
ECHO.
ECHO.
ECHO.
ECHO.
ECHO.                                               Select Windows Version
ECHO.                                   =============================================
ECHO.                                                  1. Windows 10     
ECHO.                                                  2. Windows 11 
ECHO.                                   =============================================
ECHO.
ECHO.
ECHO.

CHOICE /C:1234567890abcdefg /N
Set option=%errorlevel%

IF %option% EQU 1 ( 
	CLS
	GOTO :Win10
)	
IF %option% EQU 2 (
	CLS
	GOTO :Win11
)	

:Win11
Color 90
ECHO.
ECHO.
ECHO.
ECHO.
ECHO.
ECHO.
ECHO.
ECHO.
ECHO.
ECHO.
ECHO.
ECHO.
ECHO.                                               Windows 11
ECHO.                             =============================================
ECHO.                                           1. Windows 11 Home   
ECHO.                                           2. Windows 11 Professional
ECHO.                                           3. Citizenship
ECHO.                                           4. Start Over
ECHO.                             =============================================
ECHO.
ECHO.
ECHO.

CHOICE /C:1234567890abcdefg /N
Set option=%errorlevel%

IF %option% EQU 1 Start %~dp0MAR\Home11\Script\RunMe.bat
IF %option% EQU 2 Start %~dp0MAR\Pro11\Script\RunMe.bat
IF %option% EQU 3 Start %~dp0MAR\Cit11\Script\RunMe.bat
IF %option% EQU 4 (
	CLS
	GOTO :Begin
)	
CLS
GOTO :Win11

:Win112
Color 90
ECHO.
ECHO.
ECHO.
ECHO.
ECHO.
ECHO.
ECHO.
ECHO.
ECHO.
ECHO.
ECHO.
ECHO.
ECHO.                                               Windows 11
ECHO.                             =============================================
ECHO.                                           1. Windows 11 Professional
ECHO.                                           2. Citizenship
ECHO.                                           3. Start Over
ECHO.                             =============================================
ECHO.
ECHO.
ECHO.

CHOICE /C:1234567890abcdefg /N
Set option=%errorlevel%

IF %option% EQU 1 Start %~dp0MAR\Pro11\Script\RunMe.bat
IF %option% EQU 2 Start %~dp0MAR\Cit11\Script\RunMe.bat
IF %option% EQU 3 (
	CLS
	GOTO :Begin
)	
CLS
GOTO :Win11
