Home > Blogs > VMware PowerCLI Blog

Moving custom fields from one vCenter to another.

If you’re looking at upgrading to vSphere, one thing that may come in handy is an easy and flexible way to move custom fields from your old vCenter to your new one. With PowerCLI this is quite easy… except for one thing: there is no Get-CustomField cmdlet! The why is a long story but it turns out it’s pretty easy to write just such a thing. In fact here it is:

Not too hard at all, really. So how do we use this? One nice feature of PowerCLI that often gets overlooked is its ability to connect to multiple vCenters at once and manage them all. We can take advantage of this to connect to both our old vCenter and our new one, and move the values directly between them. The way this works is to store the output of Connect-VIServer in a variable, then pass this variable to later cmdlets to specify the server you want to manage. For example:

This next bit of code will take all custom fields on all VMs in vcserver1 and transfer them to vcserver2. This assumes the VMs already exist in both locations.

That’s really all there is to it. If you need to transfer custom fields on more than just VMs, say maybe you also have fields on ESX hosts, you can use a more general bit of code that will do this for all types of objects. I’ve added that example to my script repository and you can download it here.

8 thoughts on “Moving custom fields from one vCenter to another.

  1. Richo

    Dude your code didn’t work. “$vm” is returning $null and I am guessing it is because I have more than one custom field on each VM. The code probably works if you only have one custom field. I updated your code to reflect this. If you REMOVE your code where the loop goes through each field, and replace it with the following…

    foreach ($vm in $vms)
    foreach ($field in $fields)
    if ($vm.Name -eq $field.EntityName)
    Set-Customfield -Entity $vm -Name $field.Key -Value $field.Value

    You’re welcome.

  2. Moving home tips

    Hey! I should say thank you for the article. I really like thius article.

  3. Vigor Bio

    Have you ever thought about creating an ebook or guest
    authoring on other blogs? I have a blog based upon on the same topics
    you discuss and would really like to have you share
    some stories/information. I know my subscribers would appreciate your work.

    If you’re even remotely interested, feel free to send
    me an email.

  4. online meds

    this is very good tutrial for this
    online medicine

  5. online meds

    to get latest updates follow this
    one 2 top
    one to top

  6. Auto Indica

    Tata Motors has come a long way in terms of styling, features and powertrain technologies. The homegrown automaker is now preparing to bring more colours to its lineup in coming years. The brand has already showcased some exciting concepts in last one year and some of them will enter production soon. These include hatchback, micro-SUV, midsize sedan, SUV and electric cars as well. Performance versions of the regular cars are also on the card. Here, let us take a look at the list of upcoming Tata cars in India that we hope to see on roads soon.

  7. victor

    The most straightforward ultrabooks offered for this present year, 2019 simply will get with the investigation if honestly, on higher viewpoint anyway commendable and on general availability. There unit numerous high five light-weight Laptops inland ones that are ready to be loved by everyone.
    Coming among the fifth place is that the Microsoft Surface pc which will be an all-out antiquated workstation pc planned by Microsoft. The Italian outside material
    enriching the console to the exquisite 13.5 inches.

  8. Printable Calendar

    thanks for the code.


Leave a Reply

Your email address will not be published. Required fields are marked *