# Creating form object
Add-Type -AssemblyName System.Windows.Forms
# Get Windows version
$WindowsVersion = (Get-CimInstance Win32_OperatingSystem).Caption

#Checking if computer is windows 11
if ($WindowsVersion -match "Windows 11"){
    # Checks for tpm and secure boot, values are true or false
    try{
        $TPM = (Get-CimInstance -Namespace "Root\CIMv2\Security\MicrosoftTpm" -ClassName Win32_Tpm).IsEnabled_InitialValue
        $SecureBoot = Confirm-SecureBootUEFI
    } catch {
        $secureBoot = (bcdedit /enum {current} | Select-String -Pattern "SecureBoot") -ne $null
    }
    Write-Host $WindowsVersion

    if (($TPM -eq $false) -and ($SecureBoot -eq $false)){
        #Stop the script and inform the tech with a popup
        #@& Cscript.exe "C:\Windows\BTG_SCRIPTS\TechPrep\StatusUpdateLocal.ps1" "TPM and Secure Boot are not enabled. Please enable TPM." "Enable Secure Boot and TPM"
        [System.Windows.Forms.MessageBox]::Show("TPM and Secure Boot are not enabled. Please enable each and rerun the script.", "Error", [System.Windows.Forms.MessageBoxButtons]::OK, [System.Windows.Forms.MessageBoxIcon]::Error)
        exit 1
} elseif ($TPM -eq $false) {
        #Stop the script and inform the tech with a popup
        #& Cscript.exe "C:\Windows\BTG_SCRIPTS\TechPrep\StatusUpdateLocal.ps1" "TPM is not enabled. Please enable TPM." "Enable TPM"
        [System.Windows.Forms.MessageBox]::Show("TPM is not enabled. Please enable TPM and rerun the script.", "Error", [System.Windows.Forms.MessageBoxButtons]::OK, [System.Windows.Forms.MessageBoxIcon]::Error)
        exit 1
    } elseif ($SecureBoot -eq $false){
        #Stop the script and inform the tech with a popup
        #& Cscript.exe "C:\Windows\BTG_SCRIPTS\TechPrep\StatusUpdateLocal.ps1" "Secure Boot is not enabled. Please enable Secure Boot." "Enable Secure Boot"
        [System.Windows.Forms.MessageBox]::Show("Secure Boot is not enabled. Please enable Secure Boot and rerun the script", "Error", [System.Windows.Forms.MessageBoxButtons]::OK, [System.Windows.Forms.MessageBoxIcon]::Error)
        exit 1
    } else {
        #continue
        Write-Host "TPM Enabled: $TPM"
        Write-Host "Secure Boot Enabled: $SecureBoot"
    }
}
else {
    Write-Host "This script only runs on Windows 11. Detected OS: $WindowsVersion"
    exit 1
}
