Quick script to export or import virtual machine annotations to/from CSV format. Very handy in situation when virtual machine was unregistered and registered back in vCenter inventory. registering VM back won’t restore virtual machine annotations.
Export
Get-VM | ForEach-Object { $VM = $_ $VM | Get-Annotation |` ForEach-Object { $Report = "" | Select-Object VM,Name,Value $Report.VM = $VM.Name $Report.Name = $_.Name $Report.Value = $_.Value $Report } } | Export-Csv -Path D:\VMAnnotations.csv -NoTypeInformation
Import
Import-Csv -Path D:\VMAnnotations.csv | Where-Object {$_.Value} | ForEach-Object { Get-VM $_.VM | Set-Annotation -CustomAttribute $_.Name -Value $_.Value }
Source: http://communities.vmware.com/thread/325475