1. 程式人生 > >SCVMM 2012 R2 及應答文件BUG解決

SCVMM 2012 R2 及應答文件BUG解決

服務器 防火墻 虛擬機 管理員 操作系統

背景:

1. 計劃使用SCVMM 2012 R2自動部署win7 虛擬機模板,VM模板雖然已經使用過很多次,但是客戶端版的OS和服務器端的OS版有一點不一樣,那就是客戶端版的操作系統會默認禁用administrator 賬號,然後必須新建一個管理員賬號。

2. 計劃使用SCVMM VM 模板中的應答文件來用Unattend.xml 來默認啟用一些設置(如防火墻默認開通遠程桌面,開啟默認管理員並設置密碼),自動登錄一次默認管理員,然後執行一些命令,如配置啟動菜單(VM崩潰時好像會進入恢復模式,這樣VM重啟時需要人工介入),其他配置一些服務之類的操作。

問題: SCVMM 裏這個Win7的指定管理員賬號時,不能使用administrator ,否則部署時會報錯(10619,所提供的用戶名不是有效的該操作系統的本地管理員名稱)。

當你配置其他的賬號名稱時,SCVMM在unattend.xml 中生成一段OOBE階段的創建本地賬號的設置,如果使用administrator 那麽會和現有的administrator 沖突吧(但是奇怪的是我在對server VM 的模板上都是這樣用的,只有client 版本的有這樣的問題)。

技術分享

問題2:由於問題1 ,那麽我這裏建立的admin的賬號,我希望在VM部署後自動被刪掉。上圖的GUIRunonce的部分似乎可以做這個工作,但是問題在於GUIRunonce需要登錄一個賬號,那麽解決的話要自動登錄默認administrator賬號一次,然後執行一些默認命令如net user admin /del .

BUG 呈現:雖然以上想法在原理上沒有問題,而且我也拿unattend.xml 直接在hyper-v VM 測試下了下沒有問題,但是在用SCVMM時卻出了BUG。

1. 現象1 ,如果你再unattend.xml 中配置了autologon ,而且配置了logoncount ,那麽SCVMM最後生成合並的unattend.xml中,logonCount 會變成999次,意味著你必須還要其他手段來清除autologon,否則這個VM一直自動登錄。

2.現象2,如果你再unattend.xml 中配置了autologon 而且同時在SCVMM 中指定了 GUIRunOnce命令,那麽這個GUIRunOnce的命令在最後合成的unattend.xml 變成空白,就算你不在SCVMM的GUIRunOnce窗口中配這些命令,而是直接寫在應答文件裏,SCVMM 最後合並時也會把這些命令給變成空的。

下面是問題XML,而且在微軟的論壇中也有人提到這個BUG,似乎年代很久遠了,但是我最新的2012 r2 的版本還是問題依舊。

https://social.technet.microsoft.com/Forums/systemcenter/en-US/de874b1b-bd93-4746-a138-22422ff3717c/unattendxml-parsingmerging-issue-with-scvmm-2012-r2?forum=virtualmachinemanager

技術分享

思考及解決:

1. 如果是autologon 導致的BUG,那麽能否繞過這個部分,不用登錄賬號執行命令。有的,windows 部署完在第一次登錄賬號前,可以配置一個自定義腳本來執行命令,腳本名稱固定為setupComplete.cmd,腳本路徑在%WINDIR%\Setup\Scripts\SetupComplete.cmd, 我們只需要創建修改這個腳本即可了。

參考:

https://technet.microsoft.com/en-us/library/cc766314(v=ws.10).aspx

成品SCVMM 中用的Unattend.xml(針對32位win7),64位的win7 ,修改下processorArchitecture="x86" 中的x86 位x64,就可以了:

備註信息:XML中的產品序列號為KMS Client Key。默認開啟遠程桌面及遠程桌面對應的防火墻。默認啟用administrator 賬號,administrator 賬號的密碼部分是加密後的值,你可以在windows system image manager 中來更改加密的密碼(輸入的時候明文,寫出的是加密的密文)

<?xml version="1.0" encoding="utf-8"?>
<unattend xmlns="urn:schemas-microsoft-com:unattend">
<settings pass="specialize">
<component name="Microsoft-Windows-Shell-Setup" processorArchitecture="x86" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<ComputerName>*</ComputerName>
<RegisteredOwner></RegisteredOwner>
<ShowWindowsLive>false</ShowWindowsLive>
<RegisteredOrganization></RegisteredOrganization>
<ProductKey>FJ82H-XT6CR-J8D7P-XQJJ2-GPDD4</ProductKey>
</component>
<component name="Microsoft-Windows-TerminalServices-LocalSessionManager" processorArchitecture="x86" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<fDenyTSConnections>false</fDenyTSConnections>
</component>
<component name="Microsoft-Windows-TerminalServices-RDP-WinStationExtensions" processorArchitecture="x86" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<SecurityLayer>1</SecurityLayer>
<UserAuthentication>0</UserAuthentication>
</component>
<component name="Networking-MPSSVC-Svc" processorArchitecture="x86" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<FirewallGroups>
<FirewallGroup wcm:action="add" wcm:keyValue="RemoteDesktop">
<Active>true</Active>
<Group>@FirewallAPI.dll,-28752</Group>
<Profile>all</Profile>
</FirewallGroup>
</FirewallGroups>
</component>
<component name="Microsoft-Windows-UnattendedJoin" processorArchitecture="x86" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Identification>
<JoinWorkgroup>WORKGROUP</JoinWorkgroup>
</Identification>
</component>
<component name="Microsoft-Windows-Deployment" processorArchitecture="x86" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<RunSynchronous>
<RunSynchronousCommand wcm:action="add">
<Order>1</Order>
<Path>net user administrator /active:yes</Path>
</RunSynchronousCommand>
</RunSynchronous>
</component>
</settings>
<settings pass="oobeSystem">
<component name="Microsoft-Windows-Shell-Setup" processorArchitecture="x86" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<OOBE>
<HideEULAPage>true</HideEULAPage>
<ProtectYourPC>1</ProtectYourPC>
<NetworkLocation>Work</NetworkLocation>
</OOBE>
<RegisteredOrganization>microsoft</RegisteredOrganization>
<RegisteredOwner>microsoft</RegisteredOwner>
<TimeZone>China Standard Time</TimeZone>
<UserAccounts>
<AdministratorPassword>
<Value>Password Here ==</Value>
<PlainText>false</PlainText>
</AdministratorPassword>
</UserAccounts>
</component>
<component name="Microsoft-Windows-International-Core" processorArchitecture="x86" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<UserLocale>zh-CN</UserLocale>
<UILanguageFallback></UILanguageFallback>
<UILanguage>zh-CN</UILanguage>
<SystemLocale>zh-CN</SystemLocale>
<InputLocale>0804:00000804</InputLocale>
</component>
</settings>
</unattend>

成品 setupComplete.cmd:

@echo off

net user admin /del

bcdedit /set {default} recoveryenabled No

SCVMM 2012 R2 及應答文件BUG解決