PowerCLI: Set Custom Fields


Last week I posted a script to add Notes to a VM. After posting this script there was a little discussion on Twitter with @vmdoug, @gabvirtualworld if the Notes field is the right field to add this kind of information. So @vmdoug introduced me to the world of Custom Fields.

So I changed my CSV file and added the Field entry. This Field entry will be de name of your custom field. In my case I called it Description.

DC01,Description,Domain Controller
VC01,Description,vCenter Server

The following one-liner will fix this for you:

"D:\*.csv" | % { Get-VM $_.VMName |
Set-CustomField -Name $_.Field -Value $_.Note -Confirm:$false }

After running the script you will see the Description field with a new entry:


This one-liner will run very slow on a Large environment. So if you have large environment you should definitely check out LucD post on Alan Renouf’s Blog:  http://www.virtu-al.net


2 thoughts on “PowerCLI: Set Custom Fields

  1. Hi,

    I am trying to write a vmotion script to test the cluster configuration.. so here is what I want and I am having hard luck writting the script in Power Cli

    I want to use import-csv to do this.. I want all of my ESX host name in the CSV and then i should be able to move one of the VM to all host in the cluster for e.g.

    is this some thing you can help me with this


  2. Bom dia, estou utilizando o comando abaixo para alterar o customfields das pastas, porém não está replicando para as pastas “filho” alguém sabe como fazer isso pelo powercli?

    Get-Folder ‘nome_da_pasta’ | Set-Annotation -CustomAttribute Contato -Value e-mail


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.