Setup.ps1 加 WU 暫停/恢復;unattend.xml Order 5 收 stderr 進 log

- Setup.ps1 開頭暫停 Windows Update(PauseUpdatesExpiryTime + 停 wuauserv/UsoSvc/BITS),
  結尾解暫停 + UsoClient 觸發掃描,避免跟 post-install 搶頻寬/CPU
- Win11Debloat config 從 here-string 改成 hashtable + ConvertTo-Json,
  繞開 PowerShell 5.1 ANSI 讀取時 here-string parse 失敗的 case
- Log 函式加 Write-Host,console 視窗能即時看 START/DONE
- unattend.xml Order 5 把 stdout+stderr 全部 redirect 到 firstlogon-runsetup.log,
  Setup.ps1 連 parse error 都會留紀錄;Order 3 改空密碼 + 強制改密
This commit is contained in:
2026-04-28 08:35:20 +08:00
parent b1e5b6912a
commit ef9f5d16bc
2 changed files with 84 additions and 59 deletions

View File

@@ -169,8 +169,8 @@
</SynchronousCommand>
<SynchronousCommand wcm:action="add">
<Order>3</Order>
<CommandLine>cmd.exe /c "net user User 1234 /add &amp; net user User /logonpasswordchg:yes"</CommandLine>
<Description>建立本機帳號 User密碼 1234,首次登入強制改密</Description>
<CommandLine>cmd.exe /c "net user User /add &amp; net user User /logonpasswordchg:yes"</CommandLine>
<Description>建立本機帳號 User密碼,首次登入強制設定新密碼</Description>
<RequiresUserInput>false</RequiresUserInput>
</SynchronousCommand>
<SynchronousCommand wcm:action="add">
@@ -181,8 +181,8 @@
</SynchronousCommand>
<SynchronousCommand wcm:action="add">
<Order>5</Order>
<CommandLine>cmd.exe /c "if exist C:\Scripts\Setup.ps1 (powershell.exe -NoProfile -ExecutionPolicy Bypass -File C:\Scripts\Setup.ps1) else (echo SETUP_NOT_FOUND %DATE% %TIME% &gt; C:\Windows\Temp\firstlogon-runsetup.log)"</CommandLine>
<Description>執行 Setup.ps113 項 post-installSSH/RDP/WinRM/KMS/Chrome/Debloat/Telegram/RemoveAI/UI/IME/重命名帳號…log: C:\Windows\Temp\setup.log</Description>
<CommandLine>cmd.exe /c "(echo == firstlogon-runsetup %DATE% %TIME% == &amp; if exist C:\Scripts\Setup.ps1 (powershell.exe -NoProfile -ExecutionPolicy Bypass -File C:\Scripts\Setup.ps1) else (echo SETUP_NOT_FOUND)) &gt; C:\Windows\Temp\firstlogon-runsetup.log 2&gt;&amp;1"</CommandLine>
<Description>執行 Setup.ps1所有 stdout/stderr 都收到 firstlogon-runsetup.log含 parse error正常 Setup.ps1 自身寫到 setup.log</Description>
<RequiresUserInput>false</RequiresUserInput>
</SynchronousCommand>
<SynchronousCommand wcm:action="add">