Enthusiast
Enthusiast

Set annotation on multiple vmguests from csv file

Jump to solution

I have a csv with 2 columns. First column is a list of vmguest names and the second is an annotation I want to add to those vmguests. I basically want to add a unique key for each vmguest. So I'm using this script.

csv file

vmguestname,vmguestkey

name1,key1

name2,key2

name3,key3

script

$csv = (Import-Csv "annotations.csv")

$vmguestkey = ($csv.vmguestkey)

$vmguestname = ($csv.vmguestname)

foreach ($computer in $vmguestname){

Set-Annotation-Entity $computer -CustomAttribute "Key" -Value $vmguestkey

}

When I run the script I get a message

Set-Annotation : Cannot convert 'System.Object[]' to the type 'System.String' required by parameter 'Value'. Specified method is not supported.

Any idea what could I be doing wrong?

Tags (3)
0 Kudos
1 Solution

Accepted Solutions
Leadership
Leadership

Try like this

foreach ($computer in (Import-Csv "annotations.csv")){

    Set-Annotation-Entity $computer.vmguestname -CustomAttribute "Key" -Value $computer.vmguestkey

}


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

View solution in original post

0 Kudos
2 Replies
Leadership
Leadership

Try like this

foreach ($computer in (Import-Csv "annotations.csv")){

    Set-Annotation-Entity $computer.vmguestname -CustomAttribute "Key" -Value $computer.vmguestkey

}


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

View solution in original post

0 Kudos
Enthusiast
Enthusiast

it worked. thanks!

0 Kudos