Fix first-logon provisioning never starting
- Bound every installer wait with WaitForExit and a timeout instead of Start-Process -Wait, which in Windows PowerShell also waits for any process the installer leaves running and can block forever. This covers the VirtIO step in the answer files and the guest tools, Mesh agent and Winget installs in the scripts. - specialize pass (SYSTEM) sets ConsentPromptBehaviorAdmin=0 so nothing at first logon can stall on a UAC prompt. - Step 4 now logs to C:\ProgramData\OOBE\firstlogon.log, saves the script to C:\ProgramData\OOBE and starts it elevated in its own window. - Scripts start their transcript before the admin check, so an early stop still leaves a log. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
713463cd94
commit
f208e07d72
4 files changed
+102
-28
No files matched your search
+20
-9
@@ -3,12 +3,6 @@
|
||||
# irm https://url.isworking.fyi/oobe-desktop | iex
|
||||
# Log: C:\ProgramData\OOBE\oobe-desktop.log
|
||||
|
||||
# Check if running with elevated privileges
|
||||
if (-not ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) {
|
||||
Write-Host "Please run this script as an administrator."
|
||||
Exit 1
|
||||
}
|
||||
|
||||
$MeshAgentUrl = "https://rmm.iamchrisama.com/meshagents?id=4&meshid=zxl@U2zM95zh9ZNqah@9mUEjCJ3ptGOE6s5cjsGniacVU1fjRXtVKCKlKJN4aJQW&installflags=0"
|
||||
|
||||
$ErrorActionPreference = 'Continue'
|
||||
@@ -21,6 +15,13 @@ $WorkDir = Join-Path $env:ProgramData 'OOBE'
|
||||
New-Item -ItemType Directory -Path $WorkDir -Force | Out-Null
|
||||
Start-Transcript -Path (Join-Path $WorkDir 'oobe-desktop.log') -Append | Out-Null
|
||||
|
||||
# Check if running with elevated privileges (after the transcript starts, so this still leaves a log)
|
||||
if (-not ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) {
|
||||
Write-Warning "Not running as administrator, stopping. Rerun from an elevated PowerShell."
|
||||
Stop-Transcript | Out-Null
|
||||
Exit 1
|
||||
}
|
||||
|
||||
function Save-Download($Uri, $OutFile) {
|
||||
for ($Attempt = 1; $Attempt -le 3; $Attempt++) {
|
||||
try {
|
||||
@@ -110,7 +111,10 @@ if (Get-Service -Name 'Mesh Agent' -ErrorAction SilentlyContinue) {
|
||||
$MeshInstaller = Join-Path $WorkDir 'meshagent.exe'
|
||||
if (Save-Download $MeshAgentUrl $MeshInstaller) {
|
||||
# -fullinstall installs and starts the service without showing the install dialog
|
||||
Start-Process -FilePath $MeshInstaller -ArgumentList '-fullinstall' -WindowStyle Hidden -Wait
|
||||
$Process = Start-Process -FilePath $MeshInstaller -ArgumentList '-fullinstall' -WindowStyle Hidden -PassThru
|
||||
if (-not $Process.WaitForExit(300000)) {
|
||||
Write-Warning "Mesh Agent installer still running after 5 minutes, continuing."
|
||||
}
|
||||
}
|
||||
if (-not (Get-Service -Name 'Mesh Agent' -ErrorAction SilentlyContinue)) {
|
||||
Write-Warning "Mesh Agent service was not found after install."
|
||||
@@ -140,10 +144,17 @@ if (!(Get-NetFirewallRule -Name "OpenSSH-Server-In-TCP" -ErrorAction SilentlyCon
|
||||
}
|
||||
|
||||
# Install Winget (LTSC ships without the Store / App Installer)
|
||||
# Run in a child process: the installer script calls exit, which would end this script too
|
||||
# Run in a child process (the installer script calls exit, which would end this script too),
|
||||
# with a time limit so it can't hold up the restart. Its output goes to winget-install*.log.
|
||||
$WingetInstaller = Join-Path $WorkDir 'winget-install.ps1'
|
||||
if (Save-Download 'https://github.com/asheroto/winget-install/releases/latest/download/winget-install.ps1' $WingetInstaller) {
|
||||
& powershell.exe -NoProfile -ExecutionPolicy Bypass -File $WingetInstaller -Force
|
||||
$Process = Start-Process powershell.exe -ArgumentList '-NoProfile', '-ExecutionPolicy', 'Bypass', '-File', $WingetInstaller, '-Force' -PassThru `
|
||||
-RedirectStandardOutput (Join-Path $WorkDir 'winget-install.log') -RedirectStandardError (Join-Path $WorkDir 'winget-install-errors.log')
|
||||
if ($Process.WaitForExit(900000)) {
|
||||
Write-Output "Winget installer exited with code $($Process.ExitCode)"
|
||||
} else {
|
||||
Write-Warning "Winget installer still running after 15 minutes, continuing."
|
||||
}
|
||||
}
|
||||
|
||||
# Restart to finish OpenSSH and driver installation.
|
||||
|
||||
Reference in new issue
Block a user