SaveAndRestoreVMMMetadata

Occasionally, issues might occur where you must remove a host or host cluster from management by System Center Virtual Machine Manager (VMM). However, if you use metadata, such as custom properties, descriptions, tags, owner, or cost center, and remove the host or host cluster from management by VMM, you will lose the metadata. For one or two virtual machines, re-adding the metadata can be fairly straightforward; however, for a large number of virtual machines, it can be prohibitive. This situation only applies to VMM-specific properties. Virtualization properties, such as the amount of RAM a virtual machine is assigned, are refreshed from the host to VMM.

The scripts in this topic help you save your metadata before you remove the host or host cluster from management by VMM, and then reapply the metadata after you have re-added your host or host cluster. Use the following steps to implement these scripts in a typical scenario:

In a Windows PowerShell - Virtual Machine Manager command shell, connect to your VMM server by using the Get-VMMServer cmdlet.

After you have copied and saved the SavingVMMMetadata.ps1 script provided later in this topic, run it from the VMM command shell. The script saves your metadata into a file named exportedproperties.xml, and saves the file to the same folder from where you ran the SavingVMMMetadata.ps1 script.

秘訣

If you want metadata saved for only a particular set of virtual machines, you can modify the Get-VM cmdlet in the script to get only the virtual machines that you specify.

Remove the host or host cluster from VMM.

Re-add the host or host cluster back to VMM.

Make a full backup of the VMM database.

If you want, you can open the exportedproperties.xml file and filter it to only the virtual machines for which you want to restore the metadata. You can do this by creating a copy of the file and saving it to a different location using the same name.

If your metadata includes the UserRoleID of a virtual machine, ensure that you create the user role before you run the RestoringVMMMetadata.ps1 script.

After you have copied and saved the RestoringVMMMetadata.ps1 script provided later in this topic, run it from a VMM command shell in which you have established a connection to the VMM server. The script looks for the exportedproperties.xml file in the same location from which you run the script.

The script attempts to match an exported virtual machine with a current virtual machine in the system. For them to match, the same virtual machine with the same name has to exist on the same host. If that is the case, it applies the metadata from the XML file. Otherwise, you will receive an error if the script fails to apply the metadata. If the virtual machine cannot be found on the host, the script finishes silently without displaying an error. If the script was successful, and no errors were shown, you receive the following output:

We matched the virtual machine mytestvm1 with exported properties to an existing virtual machine on host HAMUNAPTRA.contoso.com. The current virtual machine has the VMM ID 4ea45174-4dc8-4c18-82ef-9e65f7cf552c and host-based ID B82609B7-B3FE-422A-9F8D-4456911CE0FE. The exported (old) VM has the VMM ID 0d6d4736-12c5-44af-a77e-3d5d02207835 and host-based ID B82609B7-B3FE-422A-9F8D-4456911CE0FE

The following is an example of a virtual machine from an exported XML metadata file demonstrating the properties that are exported when you run the SavingVMMMetadata.ps1 script.

# Filename: SavingVMMMetadata.ps1
# Description: Exports all metadata from the selected virtual machines. To export
# metadata for specific virtual machines, change the Get-VM command
# to retrieve only the virtual machines that you specify. The metadata
# is saved to the same folder from where you run this script, and is
# saved with the name "exportedproperties.xml".
Get-VM | select hostname, name, vmID, ID, @{Name='Custom1';Expression={$_.CustomProperties[0]}}, @{Name='Custom2';Expression={$_.CustomProperties[1]}},@{Name='Custom3';Expression={$_.CustomProperties[2]}},@{Name='Custom4';Expression={$_.CustomProperties[3]}},@{Name='Custom5';Expression={$_.CustomProperties[4]}},@{Name='Custom6';Expression={$_.CustomProperties[5]}},@{Name='Custom7';Expression={$_.CustomProperties[6]}},@{Name='Custom8';Expression={$_.CustomProperties[7]}},@{Name='Custom9';Expression={$_.CustomProperties[8]}},@{Name='Custom10';Expression={$_.CustomProperties[9]}}, CostCenter, UserRoleID, Tag, Owner, OwnerSid, Description | Export-Clixml "exportedproperties.xml"