Skip to content

11. Configuring Sysprep in Windows 11 25H2

In this exercise, a Windows 11 25H2 template is prepared using Sysprep. The goal is to ensure that cloned desktops have unique security identifiers (SIDs) and to automate the login with the unattend.xml file.

Create the base desktop

  1. Create a desktop with Windows 11 25H2 in IsardVDI.
  2. Check that the virtual machine XML is compatible (only the administrator role can edit a desktop's XML). A working example is shown below:
<domain type="kvm">
  <Name>##################</name>
  <UUID>##################</uuid>
  <Metadata>
    <libosinfo:libosinfo xmlns:libosinfo="http://libosinfo.org/xmlns/libvirt/domain/1.0">
      <libosinfo:os id="http://microsoft.com/win/11"/>
    </libosinfo:libosinfo>
  </metadata>
  <memory unit="KiB">8388608</memory>
  <currentMemory unit="KiB">8388608</currentMemory>
  <vcpu placement="static">4</vcpu>
  <os>
    <type arch="x86_64" machine="q35">hvm</type>
    <boot dev="cdrom"/>
  </os>
  <Features>
    <acpi/>
    <apic/>
    <Hypervisor>
      <relaxed state="on"/>
      <vapic state="on"/>
      <spinlocks state="on" retries="8191"/>
    </hyperv>
    <vmport state="off"/>
  </features>
  <cpu mode="host-passthrough">
    <topology sockets="1" dies="1" cores="4" threads="1"/>
  </cpu>
  <clock offset="localtime">
    <timer name="rtc" tickpolicy="catchup"/>
    <timer name="pit" tickpolicy="delay"/>
    <timer name="hpet" present="no"/>
    <timer name="hypervclock" present="yes"/>
  </clock>
  <pm>
    <suspend-to-mem enabled="no"/>
    <suspend-to-disk enabled="no"/>
  </pm>
  <Devices>
    <Emulator>/run/current-system/sw/bin/qemu-system-x86_64</emulator>
    <disk type="file" device="disk">
      <driver name="qemu" type="qcow2" cache="unsafe"/>
      <source file="/isard/storage_pools/fast/##################/groups/##################.qcow2"/>
      <target dev="vda" bus="virtio"/>
    </disk>
    <disk type="file" device="cdrom">
      <driver name="qemu" type="raw"/>
      <source file="/isard/media/##################.iso"/>
      <target dev="sda" bus="sata"/>
      <readonly/>
    </disk>
    <disk type="file" device="cdrom">
      <driver name="qemu" type="raw"/>
      <source file="/isard/media/##################.iso"/>
      <target dev="sdb" bus="sata"/>
      <readonly/>
    </disk>
    <disk type="file" device="cdrom">
      <driver name="qemu" type="raw"/>
      <source file="/isard/media/##################.iso"/>
      <target dev="sdc" bus="sata"/>
      <readonly/>
    </disk>
    <controller type="usb" model="qemu-xhci" ports="15"/>
    <controller type="pci" model="pcie-root"/>
    <controller type="pci" model="pcie-root-port"/>
    <controller type="pci" model="pcie-root-port"/>
    <controller type="pci" model="pcie-root-port"/>
    <controller type="pci" model="pcie-root-port"/>
    <controller type="pci" model="pcie-root-port"/>
    <controller type="pci" model="pcie-root-port"/>
    <controller type="pci" model="pcie-root-port"/>
    <controller type="pci" model="pcie-root-port"/>
    <controller type="pci" model="pcie-root-port"/>
    <controller type="pci" model="pcie-root-port"/>
    <controller type="pci" model="pcie-root-port"/>
    <controller type="pci" model="pcie-root-port"/>
    <controller type="pci" model="pcie-root-port"/>
    <controller type="pci" model="pcie-root-port"/>
    <console type="pty"/>
    <channel type="spicevmc">
      <target type="virtio" name="com.redhat.spice.0"/>
    </channel>
    <interface type="network">
      <source network="default"/>
      <mac address="52:54:00:5d:3c:25"/>
      <model type="e1000"/>
      <Bandwidth>
        <inbound average="15000" burst="5000" peak="25000"/>
        <outbound average="15000" burst="5000" peak="25000"/>
      </bandwidth>
    </interface>
    <input type="tablet" bus="usb"/>
    <graphics type="spice" port="-1" tlsPort="-1" autoport="yes">
      <image compression="off"/>
    </graphics>
    <sound model="ich9"/>
    <video>
      <model type="qxl" heads="1" ram="65536" vram="65536"/>
    </video>
    <redirdev bus="usb" type="spicevmc"/>
    <redirdev bus="usb" type="spicevmc"/>
    <tpm model="tpm-tis">
    <backend type="emulator" version="2.0"/>
    </tpm>
  </devices>
</domain>
  1. Once the machine is created, install the operating system as usual.

Audit mode

Note

You cannot enter audit mode if OOBE has already been completed. In this case, you must reinstall the system.

To properly prepare the image, work in audit mode.

Run the following command:

sysprep /audit /reboot

The system will restart automatically and enter audit mode. From this mode, you can:

  1. Install applications.
  2. Configure the system.
  3. Customize the environment.
  4. Create folder structures.

Configure automatic startup

To avoid the OOBE assistant and automate the session startup, you must create a file unattend.xml.

Location:

C:\Windows\System32\Sysprep\unattend.xml

Content:

<?xml version="1.0" encoding="utf-8"?>
<unattend xmlns="urn:schemas-microsoft-com:unattend"
          xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

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

      <UserAccounts>
        <LocalAccounts>
          <LocalAccount wcm:action="add">
            <Name>isard</Name>
            <Group>Administrators</Group>
            <Password>
              <Value>PASSWORD</Value>
              <PlainText>true</PlainText>
            </Password>
          </LocalAccount>
        </LocalAccounts>
      </UserAccounts>

      <AutoLogon>
        <Username>isard</Username>
        <Password>
          <Value>PASSWORD</Value>
          <PlainText>true</PlainText>
        </Password>
        <Enabled>true</Enabled>
        <LogonCount>999</LogonCount>
      </AutoLogon>

      <OOBE>
        <HideEULAPage>true</HideEULAPage>
        <HideLocalAccountScreen>true</HideLocalAccountScreen>
        <HideOnlineAccountScreens>true</HideOnlineAccountScreens>
        <SkipUserOOBE>true</SkipUserOOBE>
        <SkipMachineOOBE>true</SkipMachineOOBE>
        <ProtectYourPC>3</ProtectYourPC>
      </OOBE>

      <RegisteredOwner>isard</RegisteredOwner>
      <RegisteredOrganization>local</RegisteredOrganization>
      <TimeZone>Romance Standard Time</TimeZone>

    </component>
  </settings>

</unattend>

User Cleanup

Before running the final Sysprep, it is recommended to remove the users created during testing.

Activate the administrator account:

net user Administrador /active:yes

Set a password for it:

net user Administrador <password>

To remove user profiles, press Win + R and run SystemPropertiesAdvanced.

Open User Profiles:

Select the profile and delete it:

Afterwards, you must delete the account:

net user NomUsuari /delete

Run Sysprep

Once the system customization is finished, run:

C:\Windows\System32\Sysprep\sysprep.exe

Or directly:

sysprep /generalize /oobe /shutdown /unattend:unattend.xml

This process removes the SID, prepares the system for cloning, and automatically shuts down the machine.

Next, create a template from the desktop and, from it, create two desktops.

Verify SID

When the desktops start, check that OOBE does not appear and that the session starts automatically with the isard user.

Finally, run on each desktop:

whoami /user

Or, using PowerShell:

(Get-LocalUser -Name "isard").SID

Each machine must have a different SID, which confirms that sysprep /generalize has been applied correctly.