sysprep Windows 2008 未启用服务

sysprep Windows 2008 未启用服务

我有以下unattend.xml适用于 Windows Server 2008 R2 Enterprise 的文件。

<?xml version="1.0" encoding="UTF-8"?>
<unattend xmlns="urn:schemas-microsoft-com:unattend" xmlns:ms="urn:schemas-microsoft-com:asm.v3" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State">
    <settings pass="windowsPE">
        <component name="Microsoft-Windows-PnpCustomizationsWinPE"
        publicKeyToken="31bf3856ad364e35" language="neutral"
        versionScope="nonSxS" processorArchitecture="amd64">
            <DriverPaths>
                <PathAndCredentials
                    wcm:action="add"
                    wcm:keyValue="1">
                    <Path>C:\Windows\Temp\virtio</Path>
                </PathAndCredentials>
            </DriverPaths>
        </component>
    <component name="Microsoft-Windows-International-Core-WinPE" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
        <SetupUILanguage>
            <UILanguage>en-US</UILanguage>
        </SetupUILanguage>
            <SystemLocale>en-US</SystemLocale>
            <UILanguage>en-US</UILanguage>
            <UserLocale>en-US</UserLocale>
            <UILanguageFallback>en-US</UILanguageFallback>
    <UserLocale>en-US</UserLocale>
    </component>

        <component name="Microsoft-Windows-Setup"
            publicKeyToken="31bf3856ad364e35"
            language="neutral"
            versionScope="nonSxS"
            processorArchitecture="amd64">

            <DiskConfiguration>
                <WillShowUI>OnError</WillShowUI>
                <Disk wcm:action="add">
                    <DiskID>0</DiskID>
                    <WillWipeDisk>true</WillWipeDisk>

                    <CreatePartitions>
                        <CreatePartition wcm:action="add">
                            <Order>1</Order>
                            <Extend>true</Extend>
                            <Type>Primary</Type>
                        </CreatePartition>
                    </CreatePartitions>

                    <ModifyPartitions>
                        <ModifyPartition wcm:action="add">
                            <Format>NTFS</Format>
                            <Order>1</Order>
                            <PartitionID>1</PartitionID>
                            <Label>System</Label>
                        </ModifyPartition>
                    </ModifyPartitions>
                </Disk>
            </DiskConfiguration>

            <ImageInstall>
                <OSImage>
                    <WillShowUI>Never</WillShowUI>            
                    <InstallFrom>
                        <MetaData>
                            <Key>/IMAGE/Name</Key>
                            <Value>Windows Server 2008 R2 ENTERPRISE</Value>
                        </MetaData>
                    </InstallFrom>
                    <InstallTo>
                        <DiskID>0</DiskID>
                        <PartitionID>1</PartitionID>
                    </InstallTo>
                </OSImage>
            </ImageInstall>
            <UserData>
                <AcceptEula>true</AcceptEula>
            </UserData>
        </component>
    </settings>
    <settings pass="specialize">
        <component name="Microsoft-Windows-Shell-Setup" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
            <ShowWindowsLive>false</ShowWindowsLive>
            <TimeZone>India Standard Time</TimeZone>
        </component>
        <component name="Microsoft-Windows-TerminalServices-LocalSessionManager" processorArchitecture="amd64" 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="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
            <UserAuthentication>0</UserAuthentication>
        </component>
        <component name="Networking-MPSSVC-Svc" processorArchitecture="amd64" 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>
                <Profile>all</Profile>
                <Group>@FirewallAPI.dll,-28752</Group>
            </FirewallGroup>
        </FirewallGroups>
        </component>
    </settings>

    <settings pass="oobeSystem">

        <component name="Microsoft-Windows-Deployment" processorArchitecture="amd64" 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>
    <!--- Firewall to add IMCP -->
                <RunSynchronousCommand wcm:action="add">
                    <Order>1</Order>
                    <Path>netsh advfirewall firewall add rule name=ICMP protocol=icmpv4 dir=in action=allow</Path>
                    <Description>Add ICMP rule to enable ping on VM</Description>
                </RunSynchronousCommand>
    <!--- Command to enable cloudbase-init -->
                <RunSynchronousCommand wcm:action="add">
                    <Order>2</Order>
                    <Path>sc config cloudbase-init start= auto</Path>
                    <Description>Re-enable auto start of cloudbase-init</Description>
                    <WillReboot>Never</WillReboot>
                </RunSynchronousCommand>

            </RunSynchronous>
        </component>
        <component name="Microsoft-Windows-International-Core" language="neutral" versionScope="nonSxS" publicKeyToken="31bf3856ad364e35" processorArchitecture="amd64" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State">
            <InputLocale>en-US</InputLocale>
            <SystemLocale>en-US</SystemLocale>
            <UILanguage>en-US</UILanguage>
            <UserLocale>en-US</UserLocale>
            <UILanguageFallback>en-US</UILanguageFallback>
        </component>
        <component name="Microsoft-Windows-Shell-Setup" processorArchitecture="amd64" 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>
            </OOBE>
            <TimeZone>Coordinated Universal Time</TimeZone>
            <UserAccounts>
                <AdministratorPassword>
                    <Value>randompass</Value>
                    <PlainText>true</PlainText>
                </AdministratorPassword>
            </UserAccounts>
<!-- Auto logon is commented out -->
<!--            <AutoLogon>
                <Password>
                    <Value>randompass</Value>
                    <PlainText>true</PlainText>
                </Password>
                <Enabled>true</Enabled>
                <LogonCount>50</LogonCount>
                <Username>Administrator</Username>
            </AutoLogon>
-->
        </component>
    </settings>
</unattend>

我面临的问题是它有一个cloud-init-base服务。如果此服务是自动启动的,那么当机器重新启动或启动到不同的机器时,它会干扰sysprep进程。因此,为了完成 sysprep,我在原始映像中禁用了此服务。

现在,问题是,一旦 sysprep 完成并且机器启动,cloud-init-base服务仍然被禁用。

相同的文件在 Windows Server 2012 R2 上有效。但是,相同的 XML 构造在 Windows Server 2008 R2 上无效。如何在 oobe 阶段运行命令或在 sysprep 完成后启用服务?

答案1

您需要在机器重启后添加一个自动步骤来启用该服务。SCCM 中任务序列中的另一个步骤,或运行脚本以完成构建的“运行一次”注册表调用。无论哪种方式,任务序列(如果您使用 SCCM)或“运行一次”调用的脚本中的几个 powershell 命令(Set-Service和)都应该可以解决问题。Start-Service

相关内容