--- Sjoerd Hooft's InFormation Technology ---

User Tools

Site Tools



Recently Changed Pages:

View All Pages

View All Tags

WIKI Disclaimer: As with most other things on the Internet, the content on this wiki is not supported. It was contributed by me and is published “as is”. It has worked for me, and might work for you.
Also note that any view or statement expressed anywhere on this site are strictly mine and not the opinions or views of my employer.

Pages with comments

2019/11/18 13:52 1 Comment

View All Comments


Export and Import Custom Attributes in vCenter

When going from one vCenter to another it would be nice if you could just export all of your custom attributes to a csv file and then import them again! Powershell makes it happen again.

Note that you don't have to manually create the custom attributes when you import them, they will be created automatically.

Export Custom Attributes

This is the script for exporting the custom attributes:

$timestamp = Get-Date -format ""
$startdir = "D:\sjoerd"
$exportfile = "$startdir\vm-custom-attributes-$timestamp.csv"
$vms = Get-VM 
$Report =@()
    foreach ($vm in $vms) {
        $row = "" | Select Name, Notes, DR, "DR Value", DRStorage, "DRStorage Value", Cluster, "Cluster Value", "DataCatagory", "DataCatagory Value"
        $ = $vm.Name
        $row.Notes = $vm.Notes
        $customattribs = $vm | select -ExpandProperty CustomFields
        $row.DR = $customattribs[0].Key
        $row."DR Value" = $customattribs[0].value
        $row.DRStorage = $customattribs[1].Key
        $row."DRStorage Value" = $customattribs[1].value
        $row.Cluster = $customattribs[2].Key
        $row."Cluster Value" = $customattribs[2].value
        $row."DataCatagory" = $customattribs[3].Key
        $row."DataCatagory Value" = $customattribs[3].value    
        $Report += $row
$report | Export-Csv "$exportfile" -NoTypeInformation

Import Custom Attributes

And this is the script to import the custom attributes again from the (modified) csv file.

$startdir = "D:\sjoerd"
$importfile = "$startdir\vm-custom-attributes-adjustedforimport.csv"
$NewAttributes = Import-Csv $importfile
ForEach ($vm in $NewAttributes){
   Write-Host (get-date -uformat %I:%M:%S) "$vm is being done now..." -ForegroundColor Green
   # Set-VM -vm $vm.Name -Notes $vm.Notes -Confirm:$false
   Set-CustomField -Entity (get-vm $vm.Name) -Name $vm.DR -Value $vm."DR Value" -confirm:$false
   Set-CustomField -Entity (get-vm $vm.Name) -Name $vm.DRStorage -Value $vm."DRStorage Value" -confirm:$false
   # Set-CustomField -Entity (get-vm $vm.Name) -Name $vm.Cluster -Value $vm."Cluster Value" -confirm:$false
   Set-CustomField -Entity (get-vm $vm.Name) -Name $vm."DataCatagory" -Value $vm."DataCatagory Value" -confirm:$false
Note that the notes are also listed in the properties of the VM and are therefore kept and transferred to the new vCenter. Also note that the cluster values (ClusterInvariantVMMId) are coming from SCOM and are not required to be transferred.


Enter your comment. Wiki syntax is allowed:
customattributesvcenter.txt · Last modified: 2019/11/18 12:22 (external edit)