VMware Cloud Community
mgente
Contributor
Contributor

vSphere PowerCLI - Set VM's Annotations from csv

At our company we needed a simple script to update our VMs Annotations - It's not the best script ever but it works and I'd like to share it with the community:

# csv: VirtualMachine,Annotation,Value

# Load vmWare vSphere PowerCLI Module

Add-PSSnapin VMware.VimAutomation.Core

# Connect to vCenter

Connect-VIServer <vCenter> -User <user>

# Import CSV and Set Annotations

    Function VM-Selection {

       $vms = @()

       Import-Csv C:\vmware.csv |

       %{$vms += (Get-VM -Name $_.VirtualMachine | Set-Annotation -customattribute $_.Annotation -Value $_.Value)

       }

       return $vms

    }

VM-Selection



There are probably snipplets where you can find something similar - thanks for their great work!

Tags (2)
Reply
0 Kudos
2 Replies
nimos001
Enthusiast
Enthusiast

Hmm, Interesting. I have a problem in my environment where administrators are not updating the 'notes' field but we do seem to have a server patching excel document that lists what the application is and who the owner is. I need to take a look at what you have here and see if I can make something like this work in my environment. If I can just import a couple of the columns for each VM in a nice format that would be a huge WIN!

Edit: I have attached an example of what I am talking about. I want to import the 'Server Name' and 'Manager' fields into the notes section for the associated VM. (Not sure if I can put them on separate lines in the notes section)

Reply
0 Kudos
nimos001
Enthusiast
Enthusiast

I guess I am not wanting to actually set a custom attribute though, just wanting to populate the notes field.

Reply
0 Kudos