Last active
April 19, 2025 08:50
-
-
Save Grayda/7f1cb37324360c4f23d6da9e3eb8713c to your computer and use it in GitHub Desktop.
Autopilot / Intune onboarding BadKB scripts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
REM This script automates the Windows 11 installation from a USB stick. | |
REM You'll probably need to adjust the delays to match your hardware, | |
REM because each machine takes a different amount of time to load various screens | |
DEFAULTDELAY 300 | |
REM Move to the locale selector and select English (Australia), then press Next and then Install Now | |
TAB | |
STRING English (Australia) | |
ALT N | |
ALT I | |
REM Wait 10 seconds for the "Setup is starting" to go through | |
DELAY 10000 | |
REM Tab down to "I don't have a product key" and press Enter. | |
TAB | |
TAB | |
TAB | |
ENTER | |
DELAY 5000 | |
REM Accept the license, go next, go to custom install | |
ALT A | |
ALT N | |
ALT C | |
REM Wait, then move to the top of the list of drives | |
DELAY 500 | |
HOME | |
REM Delete the first drive, then go back to the top of the list and go down one. | |
ALT D | |
LEFT | |
ENTER | |
HOME | |
DOWN | |
REM Repeat for the second drive | |
ALT D | |
LEFT | |
ENTER | |
HOME | |
DOWN | |
REM And the third drive | |
ALT D | |
LEFT | |
ENTER | |
HOME | |
DOWN | |
REM And the fourth drive if it exists. If it doesn't, these keys don't do anything anyway | |
ALT D | |
LEFT | |
ENTER | |
HOME | |
REM Start the install | |
ALT N |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
REM This script retrieves a device hash from a Windows machine that has had a clean Windows 11 installation done. | |
REM Here's how to use this: | |
REM 0. Edit this script. You'll want to set the GroupTag parameter, and possibly change the drive letter where the file is outputted if you have a DVD drive in the machine or something else that means D: isn't the USB stick. | |
REM 1. Create a Windows 11 installation USB using the media creation tool | |
REM 2. Install Windows 11 (see the WIN11-INSTALL.txt BadKB script if you want to automate that too) | |
REM 3. When the computer reboots to the OOBE screen, run this script | |
REM 4. It will press Shift+F10 to bring up a command prompt, then run all of this. Make sure that the USB stick is still plugged in and the drive is D: | |
REM If the command prompt isn't the active window, cancel the script and run it again so that the command prompt is the active window | |
REM 100ms delay between button presses by default | |
DEFAULTDELAY 100 | |
REM Open Command Prompt | |
SHIFT F10 | |
REM For some reason, command prompt isn't focused when you open it, so we alt-double-tab to make it active | |
HOLD ALT | |
TAB | |
DELAY 100 | |
TAB | |
RELEASE ALT | |
DELAY 1000 | |
REM Next, we make and CD into the powershell scripts folder. We do this to make sure that the script actually runs | |
STRINGLN mkdir "C:\Program Files\WindowsPowerShell\Scripts" & cd /D "C:\Program Files\WindowsPowerShell\Scripts" | |
REM Next we run the powershell script. The following command does several things: | |
REM 1. Check for an internet connection (and halt until it's available) | |
REM 2. Sets the timezone. | |
REM 3. Installs NuGet as a package provider. This is where the Get-WindowsAutoPilotInfo script is hosted | |
REM 4. Installs the Get-WindowsAutoPilotInfo script | |
REM 5. Run the Get-WindowsAutoPilotInfo command and outputs it to autopilot_temp.csv (and sets the group tag to AutopilotDevice) | |
REM 6. Converts the file into ASCII. If we don't do this, Excel just sees it as a .txt file and Intune tells us the file is formatted incorrectly. | |
REM 7. Shuts down after 60 seconds once hash is grabbed. | |
STRINGLN PowerShell -NoProfile -ExecutionPolicy Unrestricted -Command Write-Host "Checking internet. Won't continue until connected"; while ($true) { if (Test-Connection -comp microsoft.com -count 1 -quiet) { Write-Host "Connected. Waiting 5 secs"; Start-Sleep -Seconds 5; break } elseif ($Error[0].Exception.Message -match 'No such host') { continue } else { Write-Host 'Error. Reconnect network adaptor, press key when ready'; [System.Console]::ReadKey() ^| Out-Null } }; Set-Timezone -Name 'AUS Eastern Standard Time'; Enable-PSRemoting -SkipNetworkProfileCheck -Force; Install-PackageProvider -Name NuGet -Confirm:$false -Force:$true; Install-Script -Name Get-WindowsAutoPilotInfo -Confirm:$false -Force:$true; .\Get-WindowsAutopilotInfo.ps1 -GroupTag AutopilotDevice -ComputerName $env:computername -OutputFile d:\tmp.csv -Append; Get-Content -Path d:\tmp.csv ^| Out-File -FilePath d:\autopilot.csv -Encoding ascii; Write-Host 'Shutting down in 1 min. Press Ctrl+C to stop'; Start-Sleep -Seconds 60; Stop-Computer |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks! Nice script