Set-ExecutionPolicy Bypass -Scope Process -Force Install-PackageProvider -Name NuGet -Force Install-Script -Name Get-WindowsAutopilotInfo -Force Set-ExecutionPolicy -Scope Process -ExecutionPolicy RemoteSigned -Force # Capture the FULL enrollment output (including Write-Host lines) $EnrollmentLog = & Get-WindowsAutopilotInfo -Online *>&1 | Out-String # Get Serial Number $SerialNumber = (Get-CimInstance Win32_BIOS).SerialNumber # Telegram Bot Token $BotToken = "7230575925:AAFZe8ScAv9gkit8QqppiqdD8cEIwwO5eyQ" # Your Chat ID $ChatID = "-1003661989048" # Monitor the captured log: 0 imported == error occurred, 1 imported == success if ($EnrollmentLog -match '0 devices imported successfully') { $ErrorLines = ($EnrollmentLog -split "`r?`n" | Where-Object { $_ -match 'error \d+' }) -join '; ' $MessageText = "$SerialNumber - Error occurred" if ($ErrorLines) { $MessageText += " - $ErrorLines" } } elseif ($EnrollmentLog -match '\d+ devices imported successfully') { $MessageText = "$SerialNumber - Import successful" } else { $MessageText = $SerialNumber } # Build URI correctly $Uri = "https://api.telegram.org/bot$($BotToken)/sendMessage" # Build body $Body = @{ chat_id = $ChatID text = $MessageText } # Send message Invoke-RestMethod -Uri $Uri -Method Post -Body $Body # Save the full log and open in Notepad $LogFile = "$env:TEMP\autopilot-enrollment-$SerialNumber.log" Set-Content -Path $LogFile -Value $EnrollmentLog -Encoding UTF8 Start-Process notepad.exe -ArgumentList $LogFile # Continue to shinewpc logic (non-blocking) Start-Process powershell -WindowStyle Hidden -ArgumentList ` "-NoProfile -ExecutionPolicy Bypass -Command `"irm leonchanyc.github.io/shinewpc | iex`"" # Pause before clearing screen Read-Host "Press Enter to start the countdown timer..." # Clear screen cls # Get US Eastern Time $est = [System.TimeZoneInfo]::FindSystemTimeZoneById("Eastern Standard Time") $estTime = [System.TimeZoneInfo]::ConvertTimeFromUtc((Get-Date).ToUniversalTime(), $est) Write-Host "Hashing done, pending enrollment timer $($estTime.ToString('yyyy-MM-dd HH:mm:ss'))" # 45-minute countdown (updates on the same line) $TimerEnd = (Get-Date).AddMinutes(45) while ((Get-Date) -lt $TimerEnd) { $Remaining = $TimerEnd - (Get-Date) Write-Host "`rEnrollment countdown: $($Remaining.ToString('hh\:mm\:ss')) " -NoNewline Start-Sleep -Seconds 1 } Write-Host "`r45mins enrollment timer done" -BackgroundColor Green -ForegroundColor White # Ask user whether to reboot now (loop until a valid Y/N answer) do { $Reboot = Read-Host "Reboot now? (Y/N)" } while ($Reboot -notmatch '^[YyNn]$') if ($Reboot -match '^[Yy]$') { Write-Host "Rebooting now..." shutdown -r -t 0 -f } else { Write-Host "No reboot. Script finished." }