Automation

 View Only
Expand all | Collapse all

Set annotation on multiple vmguests from csv file

  • 1.  Set annotation on multiple vmguests from csv file

    Posted Aug 02, 2017 08:23 AM

    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?



  • 2.  RE: Set annotation on multiple vmguests from csv file
    Best Answer

    Posted Aug 02, 2017 08:32 AM

    Try like this

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

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

    }



  • 3.  RE: Set annotation on multiple vmguests from csv file

    Posted Aug 02, 2017 08:55 AM

    it worked. thanks!