hi everyone, this week i am going to post a new set of PowerShell scripts that will allow you to save the Virtual Machine metadata in VMM. The saved metadata can be applied later on in the event that you add and remove the host from VMM management.
A scenario where this issue comes up is when something goes wrong with your host in VMM and you need to remove it from management and re-add it to VMM (the host can also be a cluster). Typically in a situation like this you will loose all the metadata associated with your virtual machines. Such metadata includes the custom properties, descriptions, tags, owner, cost center, etc. If it is 1 or 2 VMs, its not a big deal to add them back, but when you are talking about a cluster with 200 VMs it is quite an effort. The scripts i am posting today will enable you to save the metadata and then restore them. Be aware that i am calling VMM metadata here only the properties that are VMM specific. Any virtualization properties of a virtual machine like the amount of RAM it is assigned are already dealt with by VMM. The VMM refreshers will refresh this information from the virtualization host into VMM :). So rest assured for that case.
A typical workflow will look like this.
<<
We matched the VM mytestvm1 with exported properties to an existing VM on host HAMUNAPTRA.contoso.com. Current VM has VMM ID 4ea45174-4dc8-4c18-82ef-9e65f7cf552c and host-based ID B82609B7-B3FE-422A-9F8D-4456911CE0FE. Exported (old) VM has VMM ID 0d6d4736-12c5-44af-a77e-3d5d02207835 and host-based ID B82609B7-B3FE-422A-9F8D-4456911CE0FE
>>
12. Voila, you are now done :). Good luck.
Below is a sample VM from an exported XML metadata file. You can see here the properties we export as part of this script.
<Objs Version="1.1.0.1" xmlns="http://schemas.microsoft.com/powershell/2004/04"> <Obj RefId="0"> <TN RefId="0"> <T>Selected.Microsoft.SystemCenter.VirtualMachineManager.VM</T> <T>System.Management.Automation.PSCustomObject</T> <T>System.Object</T> </TN> <MS> <S N="HostName">HAMUNAPTRA.contoso.com</S> <S N="Name">mytestvm1</S> <S N="VMId">B82609B7-B3FE-422A-9F8D-4456911CE0FE</S> <G N="ID">0d6d4736-12c5-44af-a77e-3d5d02207835</G> <S N="Custom1">custom1</S> <S N="Custom2">custom2</S> <S N="Custom3">custom3</S> <S N="Custom4">custom4</S> <S N="Custom5">custom5</S> <S N="Custom6">custom6</S> <S N="Custom7">custom7</S> <S N="Custom8">custom8</S> <S N="Custom9">custom9</S> <S N="Custom10">custom1000</S> <S N="CostCenter">19997374509</S> <G N="UserRoleID">ad564691-85eb-40a5-9d5f-166c919d645d</G> <S N="Tag">vmuniquetag</S> <S N="Owner">contoso\enduserforVMM1</S> <S N="OwnerSid">SIDVALUEGOESHERE</S> <S N="Description">this is a test description</S> </MS> </Obj></Objs>
SavingVMMetadata.ps1 --> copy the contents below into the PowerShell script file "SavingVMMetadata.ps1"
# Export Time# This PowerShell script will export all metadata from the selected VMs.# To export metadata only for some specific VMs and not all VMs in the system, simply change the get-vm call below to a more targeted PowerShell script# that will enable you to only save the metadata for the VMs you want to.# metadata is saved on the same folder where you run this script under the name exportedproperties.xmlget-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"