Easy way to Sysprep a VM in Azure

 What is Sysprep ?

Sysprep is a Windows System Preparation Tool that is used to prepare a Windows installation (Windows operating system) for duplication, auditing, and customer delivery. Sysprep is run on a reference computer, which is then cloned to create identical installations. Sysprep removes system-specific information such as the computer SID and computername, as well as drivers and other system-specific data, allowing the duplicated installations to run as individual computers with their own SIDs and computernames.

How to generazlize a VM in Azure using Sysprep:

Lets assume that you have restored/cloned a virtual machine.

Now your existing VM and a new clone VM, both will have a same SID number.

What is SID ?

A SID (Security Identifier) is a unique identifier assigned by the operating system to every account on a Windows system. Each SID is a unique identifier that is used to control access to resources, such as files, registry keys, and network resources. The SID is also used to identify the user in the security audit logs. The SID for each user account is created when the account is created, and it cannot be changed. When a computer is cloned, each copy of the computer has identical SIDs, which can cause problems with accessing resources and generating accurate security audit logs. Sysprep is used to change the SIDs on cloned computers so that each computer has a unique SID.

To avoid future connection to the VM, we need to use sysprep tool to make the VM as unique.

In Azure, once the VM is cloned/restored to the target resource group.

Go to VM, select overview > connect the VM using your credentials.




Once you logged in to the clone VM, go to run and type : sysprep



Now here we will create an xml file on this location.

Let me tell you why we need this file, so once you run the sysprep the VM will shutdown.

After you turn on this VM it will ask for some user inputs like language, region, etc.

Since it is Azure virtual machine you cant provide those inputs from Azure portal.

hence we provide the inputs in the answer.xml file and shut it down.

Next, when we power it on, those inputs are pulled from answer.xml 


So lets create a file answer.txt and copy/paste the below lines and save as type .xml

<?xml version="1.0" encoding="utf-8"?>
<unattend xmlns="urn:schemas-microsoft-com:unattend">
  <settings pass="oobeSystem">
    <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>
        <SkipMachineOOBE>true</SkipMachineOOBE>
        <SkipUserOOBE>true</SkipUserOOBE>
      </OOBE>
    </component>
  </settings>
</unattend>


Save the file as answer.xml and save type as all file.




Now open a command prompt and go to the below path 
Go to run > type : cmd













Now copy/paste the below command :
sysprep /generalize /oobe /unattend:answer.xml /shutdown
Now you will mention the answer.xml file on the above command.


Now the below process will take 5 mintues.






Once you rdp connection is ended, go to azure portal > check the status of the VM, it should be stopped.



Then, click on stop, once it is successfully stopped start the VM and access using your existing credentials.

Now your VM is successfully generalized.


Post a Comment

0 Comments