Digital Nervous System Making Incredible Software, Incredibly Simple

Import and Export VMM 2012 Metadata

A number of years back, in the era of VMM 2008, a smart cookie from Microsoft called “Michael Michael” (or M2) , published an article on exporting and importing VM data ( in the event you needed a hammer and sledge option for resolving unnamed issues.

The concept of article still stands very true in VMM 2012 and 2012 SP1, however there are some additional export features now embedded in the product also which one could leverage. However, as things happen I recently had a requirement of backing out a cluster of nodes from my VMM server with all the VMs intact, to address an issue, before reading the cluster and all its VMs back under VMMs management scope again.

The price of such a move was that I would no longer have any metadata on these VMs once SCVMM re-enrolled them the environment including roles, quotas, clouds, etc. This as you can imagine in a private cloud is not going to cut any mustard, and I was under a very small outage window.

Hence, I took the opportunity to rev the code from “Michael Michael”, and make it VMM 2012 aware.

Now before you start spamming that this code is not sexy PowerShell, I remind you that I was under the gun, and did not have time to refactor into functions etc, and figured that sharing this would save you some time in the case of an emergency also. It might not be pretty, but it works.

Export Metadata

Right, enough waffle, lets dump the data to an XML File, which I am placing in the current folder and calling exportedproperties.xml. In addition I am filtering the hosts which I am exporting from, as I have a LOT of them, and really only need to care about the nodes which need attention. You can remove this filter or update to match your environment by editing the match clause in this section of the command “? {$.HostName -like “hyperv*”}”, Replacing _hyperv* with your own wildcard string

#Code to export the metadata of the Virtual Machines on the cluster

get-vm | ? {$.HostName -like
“hyperv*”} | 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]}}, OwnerSid, Tag, CostCenter, SelfServiceUserRole, OperatingSystem, QuotaPoint, UserRole, UserRoleID, Owner, Description, cloud| export-clixml

Import the Metadata

After you have removed and reimported the nodes back into VMM, we need to look at the restore code, you can paste as is, or place it in a file for example RestoreMetadata.PS1. Again, the data file is in my current folder and called exportedproperties.xml

Hope this saves you a little time (and hair)

Be social and share this post!
Share via OneNote