Automation

 View Only
  • 1.  automate updating of customfield

    Posted Jan 13, 2016 06:54 AM

    Hi Experts,

    I need help with automating the updating of annotation custom attributes by importing the name of the VM on the first column and applying the new value on the product field on the 2nd column from a csv file.

    (csv file)

    Name | Product

    VM1   | test1

    VM2   | test2

    The annotation custom attribute should be:

    (Summary Annotations section)

    VM1 > Product: test1

    VM2 > Product: test2

    what i have in mind is import from csv the name and values then run a loop of this

    Get-VM VM2 | Set-CustomField -Name Product -Value test1

    Many thanks.

    Cheers



  • 2.  RE: automate updating of customfield
    Best Answer

    Posted Jan 13, 2016 07:43 AM

    You mean something like this ?

    foreach($row in (Import-Csv -Path input,csv -UseCulture)){

        Get-VM -Name $row.Name | Set-CustomField -Name Product -Value $row.Product

    }



  • 3.  RE: automate updating of customfield

    Posted Jan 13, 2016 08:33 AM

    Thanks Luc that did the trick. If i want to update multiple customfield what do i need to do? do i pipe another set-customfield?



  • 4.  RE: automate updating of customfield

    Posted Jan 13, 2016 08:48 AM

    If you want to have all the custom fields in 1 CSV file, you could do something like this

    # CSV layout

    #

    # VM,CField1,CField2,CField3

    # vm1,field11,field21,field31

    # vm2,field12,field22,field32

    #

    $t.psobject.Properties | where{$_.Name -ne 'VM'} | %{

        $_

    }

    foreach($row in (Import-Csv -Path input,csv -UseCulture)){

        $vm = Get-VM -Name $row.VM

        $row.psobject.Properties | where{$_.Name -ne 'VM'} | %{

            Set-CustomField -Entity $vm -Name $_.Name -Value $_.Value

        }

    }