Re-Customize Existing Virtual Machine: Best Solution is PowerCLI Script!
What do you do if have to re-customize multiple virtual machines because of human mistake during creation or anything else?
I had situation that I had to re-customize virtual machines and I couldn’t create virtual machines again.
What Was Exact Problem?
This was our scenario:
Some virtual machines exported from a vCenter and we had to import them to another vCenter.
As the machines MAC addresses had been changed after restoring them to another vCenter, the machines network configurations were incorrect.
We didn’t have the machines root password and we couldn’t re-configure network configuration files in the machines manually.
Re-Customize Existing Virtual Machine, is it possible?
Answer is yes. vCenter allows you to re-customize existing virtual machines with information of “Customization Specification”. This feature is available for single virtual machine via virtual machine’s menu. You just need to have downtime for the virtual machine because virtual machine will be powered off and power-on to re-customization complete.
What About Multiple Virtual Machines?
Don’t worry about the same situation, if you had customized your machine by a “Customization Specification” in vCenter and you didn’t change other network configuration files such as hosts file and others, you can re-customize the machine without having root password and also do it automatically.
The solution is: PowerCLI script!
At the first step, you have to customize network mapping of your customization specification:
Get-OSCustomizationSpec -Name $OSSpec | ` Get-OSCustomizationNicMapping | ` Set-OSCustomizationNicMapping -IpMode:UseStaticIP -IpAddress $IP -SubnetMask $Mask -DefaultGateway $Gateway
You must replace network specifications in the above script.
At the second step, you have to shut down the machine and then run the below command:
Get-VM -Name $VMName| Set-VM -OSCustomizationSpec $OSSpec
Power on your machine and the customization will be applied on your machine again.
You can change the script for re-customizing multiple virtual machines by adding For loop to the script or repeat the above script with different values for multiple virtual machines.