Thursday, January 5, 2012

Vsphere PowerCLI script to clone and customize Windows guest OS

VMware can also customize Windows guest OS by Windows sysprep tool, though the process is more complex than Linux guest OSThere are two options to clone and “sysprep” VMware Windows guest OS:1.Install sysprep tools in Windows guest OS and run sysprep.exe in guest OS command line, then clone it by VMware2.Install sysprep tools in Virutal Center and let VMware tools in Windows guest in to control sysprep process either by GUI or script. (It seems sysprep rely on VMware tools, so the VMware tools must be installed in guest OS)

Option #2 is the preferred method, because you can use script to easily customize unique information e.g computer name, ip addresses etc.

Install sysprep tools in Virtual CenterVMware KB: Sysprep file locations and versions Windows Vista onwards(vista/2008/7/2008R2/) don’t need this step, because its sysprep is built-in.Create guest customization by GUI Virtual Center -> view-> management -> “customization specification manager”. Create a new customization and select it when asked for guest customization information in GUI clone action. Create guest customization by script. Customization by GUI is not flexible, customization by script can be created on the fly. The following is enhancement to the clonevm.ps1 in Vsphere PowerCLI script to clone and customize Linux guest OS, just replace the “Identity for Linux” part with following code block

write-host "Unknown ostype: $s_ostype. Please set it to linux or windows"

exit

}

}

NOTES: - The guest OS(Windows/Linux) will be forcefully rebooted by Vmware tools again in ~1 minute after you power it on, so don’t login in a hurry to check the result. - The script only works in a live session to Virtualcenter, it doesn’t work in a direct login session to ESX host.

I haven't tested joining domain.Did join domain fail with PowerCLI? You may try to test with "customization specification manager" first and use the latest sysprep tools as listed in the http://kb.vmware.com/kb/1005593.