在虛擬機部署、磁碟克隆、映像佈署場景中,Windows Server 2008 R2 **無法使用舊工具 NewSID** 修改 SID (Security Identifier),強行使用會導致藍畫面。微軟官方唯一支援方式是 **Sysprep (系統準備工具)**。本文記錄完整操作流程、關鍵參數、常見錯誤與無人值守應答檔進階用法。
CRITICAL_PROCESS_DIED 等)。C:\Windows\System32\Sysprep\sysprep.exe。psgetsid 記錄機器 SID 與使用者 SID,供事後驗證。C:\Users、C:\ProgramData 若有 EFS 加密、NTFS 壓縮、連結點,Sysprep 會失敗。C:\Windows\System32\Sysprep\sysprep.exe。psgetsid 驗證機器 SID 已改變。cd C:\Windows\System32\Sysprep
sysprep /generalize /oobe /reboot
/generalize:移除機器特有資訊 (SID、驅動、事件記錄等)。/oobe:重啟進入全新體驗模式。/reboot:自動重啟 (可改 /shutdown / /quit)。sysprep /generalize /oobe /shutdown /unattend:unattend.xml (配合應答檔)。Sysprep 後預設會失效:使用者設定檔、網路設定、Windows 啟用、時區、鍵盤、IE/Edge 設定等。使用 unattend.xml 可自動填入,保留所需配置。
<?xml version="1.0" encoding="utf-8"?>
<unattend xmlns="urn:schemas-microsoft-com:unattend">
<settings pass="generalize">
<component name="Microsoft-Windows-Security-SPP" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS">
<SkipRearm>1</SkipRearm> <!-- 避免重置授權倒數,最多 3 次 -->
</component>
<component name="Microsoft-Windows-PnpSysprep" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS">
<PersistAllDeviceInstalls>true</PersistAllDeviceInstalls> <!-- 保留已安裝驅動 -->
</component>
</settings>
<settings pass="oobeSystem">
<component name="Microsoft-Windows-International-Core" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS">
<InputLocale>zh-TW</InputLocale>
<SystemLocale>zh-TW</SystemLocale>
<UILanguage>zh-TW</UILanguage>
<UserLocale>zh-TW</UserLocale>
</component>
<component name="Microsoft-Windows-Shell-Setup" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS">
<OOBE>
<HideEULAPage>true</HideEULAPage>
<HideWirelessSetupInOOBE>true</HideWirelessSetupInOOBE>
<HideLocalAccountScreen>true</HideLocalAccountScreen> <!-- 跳過建立本地帳號,直接用內建 Administrator -->
<ProtectYourPC>3</ProtectYourPC> <!-- Windows Update 設定:3=不建議 -->
</OOBE>
<RegisteredOrganization>MyOrg</RegisteredOrganization>
<RegisteredOwner>Admin</RegisteredOwner>
<TimeZone>Taipei Standard Time</TimeZone>
</component>
</settings>
<settings pass="specialize">
<component name="Microsoft-Windows-Shell-Setup" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS">
<ComputerName>*</ComputerName> <!-- * = 隨機產生 -->
</component>
</settings>
</unattend>
sysprep /generalize /oobe /reboot /unattend:C:\unattend.xml
建議用 Windows SIM (Windows System Image Manager) (Windows ADK 內建) 建立/驗證 unattend.xml,避免語法錯誤導致 Sysprep 失敗。
| 錯誤現象 | 原因 | 解決 |
|---|---|---|
| Sysprep 執行後卡住/報錯「A fatal error occurred while trying to sysprep the machine」 | 安裝了 Windows Store 應用 (Modern Apps) 且未移除 | PowerShell 移除所有 Provisioned AppxPackage:Get-AppxProvisionedPackage -Online | Remove-AppxProvisionedPackage -Online,或 unattend.xml 加入 Microsoft-Windows-Appx\Package\Remove |
| 重啟後藍畫面 / 進不了 OOBE | 驅動不相容 / 硬體抽象層 (HAL) 不匹配 / 加密資料夾 | 移除第三方驅動、解密資料夾、確認 PersistAllDeviceInstalls 設定 |
| Windows 啟用狀態重置 / 授權倒數歸零 | /generalize 會觸發重置 (SkipRearm=0 時) | 加入 SkipRearm=1 (最多 3 次);或使用 KMS/MAK 批量啟用環境 |
| 網路設定 (靜態 IP、DNS、防火牆規則) 遺失 | Sysprep 預設不保留 | unattend.xml 在 specialize 階段配置 Microsoft-Windows-TCPIP、Microsoft-Windows-Firewall;或腳本重設 |
psgetsid
# 或
whoami /user
# 或 PowerShell
(Get-WmiObject Win32_ComputerSystem).Name + " : " + (New-Object System.Security.Principal.SecurityIdentifier (Get-ItemProperty "HKLM:\SECURITY\SAM\Domains\Account").V).Value
比對執行前記錄的 SID,機器 SID (S-1-5-21-... 結尾為 -500/-501 等) 應已改變。
Windows Server 2008 R2 修改 SID **唯一正途是 Sysprep**。掌握 /generalize /oobe /reboot 基礎指令,善用 unattend.xml 保留關鍵配置、自動化 OOBE,並配合 SkipRearm、PersistAllDeviceInstalls 避開常見坑點。操作前**快照備份、記錄 SID、準備驅動**,事後**驗證 SID 變更、補裝驅動、重新啟用、還原服務**,即可安全完成克隆/部署任務。
高效管理 Windows Server 2008 磁碟區陰影複製:vssadmin 指令實戰
Windows Server 2008 企業版啟用/激活方法紀錄:slmgr 指令、重設授權、正版驗證
Windows Server Core 便捷操作與遠端管理:自訂提示符、快速列出設定指令、啟用遠端 MMC/WinRS 管理通道
Windows Server 2008 域管理新體驗:RODC 與角色分離
Windows Server 2008:贏在企業實戰的「雙胞胎兄長」——超越 Vista 與 Linux 的關鍵優勢