Salvaging virtual machines created in SCVMM, when deleting the SCVMM template based lab environment in TFS.

We had a customer who had used imported SCVMM template within Lab Management to create new environments and due to some business need, he had to delete those environments and recreate them with the same machines. The environments had to be new, but the machines had to be in the same current state. However, it wasn’t as straight forward as deleting the environments and then recreating new ones with the same SCVMM template.

Deleting a template backed environment within TFS Lab Management, results in a deep destroy – the VMs that correspond to the environment are deleted from SCVMM.
“If you delete an imported virtual machine or a template in Microsoft Test Manager, the underlying virtual machine or the template is not deleted in SCVMM. If you delete a stored virtual machine or template that was created from a virtual machine in a deployed environment, the stored virtual machine or template is deleted.” -

Deletion of the machines, in this scenario is by-design and expected behavior. If the templates used are already customized and need not much effort to recreate an identical new machine with the same environment, there wouldn’t have been a problem. Issue came up because the template used was a stock – image template to create the basic features like OS.

Customer wanted to retain the machines and make them a part of new environments. He had spent a lot of time on those machines, customizing them and reverting back to the template would mean loss of a man hours. Also there were a lot of machines and re-installing the software on all of them wasn’t an ideal solution.

We found a few possible work around, during our discussions, which we thought would be good to blog about, in case someone ran into this scenario.

Option 1 - Cloning the machine in SCVMM -

We could create a copy of the VMs that would be deleted from the SCVMM side, then delete the environments. Later can use the cloned machines to create the new environments.
However this method has a few restrictions from the SCVMM side. For example additional steps need to be taken for a domain joined machine as the cloned virtual machine has the same computer name as the source virtual machine and could cause issues. You can look into this link for details and discuss this option with your SCVMM admin for chalking a plan out.

Option 2 –
Taking a backup of the Hyper-V machine

· Export the VM in Hyper-V, and also made a copy of the vhdx file of the machine.
· Delete the environment from MTM, this deleted the machine from Hyper-V host/ SCVMM.
· Create a new virtual machine in Hyper-V and used the vhdx file of the initial machine.
· Virtual machine is created with a new name in Hyper-V (but the actual machine name remains the same as old one)
· Create new lab environment successfully with the newly created VM.

One of the major downside that involves deleting and recreating environments, is the snapshot history is lost within TFS (remains intact within SCVMM or Hyper-V). TFS wouldn’t recognize the past snapshots that are present on the machines in the environment. The same applies to this scenario also – something that you should consider before proceeding. TFS won’t recognize the snapshots in both the methods (option 1 and option 2).

Content created by – Venkata Narasimhan
Content reviewed by – Romit Gulati

Comments (0)

Skip to main content