VMware Cloud Community
madpro
Enthusiast
Enthusiast
Jump to solution

Adding multiple Annotations to a VM

Hi

I have several Annotations I want to add to a VM using Powercli, and a csv

In the csv I have

CustomeAttribute,Value

Customisation,Win10

IP,192.168.0.1

In the script

$attributes = Import-Csv C:\CustomAttribute.csv -Header ("CustomAttribute","Value")

foreach ($attribute in $attributes){

          

           Set-Annotation -Entity VMNAME  -CustomAttribute $_.CustomAttribute -Value $_.Value

}

I keep getting an error

Set-Annotation : Cannot validate argument on parameter 'CustomAttribute'. The argument is null. Provide

a valid value for the argument, and then try running the command again.

Can anyone help please?

Thanks

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Try your loop like this

foreach ($attribute in $attributes){

    Set-Annotation -Entity (Get-VM -Name VMNAME-CustomAttribute $attribute.CustomAttribute -Value $attribute.Value

}


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

0 Kudos
4 Replies
LucD
Leadership
Leadership
Jump to solution

Try your loop like this

foreach ($attribute in $attributes){

    Set-Annotation -Entity (Get-VM -Name VMNAME-CustomAttribute $attribute.CustomAttribute -Value $attribute.Value

}


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
madpro
Enthusiast
Enthusiast
Jump to solution

That worked perfectly..

So, calling attribute.customattribute pulls that data from the row in the CSV?

Thanks

0 Kudos
LucD
Leadership
Leadership
Jump to solution

You already imported the content of the CSV in the array $attributes.

Then with the ForEach loop you take the content of that array row by row, and each row is stored in the variable $attribute.

Each column in the CSV is a property on each row object, and you retrieve the values of the two columns by addressing the properties $attribute.CustomAttribute and $attribute.Value


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

madpro
Enthusiast
Enthusiast
Jump to solution

Great explanation, thanks

0 Kudos