Automation

 View Only
  • 1.  Updating Notes field from a csv

    Posted Jan 19, 2015 09:42 PM

    Hello,

    I would like to update the Notes field for all the VMs in my environment from a .csv file.  To do this I did and export of my environment to a .csv file by using this command:

    Get-VM | Select Name, Notes | Export-Csv -path "c:\output\notes.csv" -NoTypeInformation

    I have now have list of all VMs and their existing Notes.  I manually modified the notes fields keeping the existing and adding descriptions for all the VMs which didn't have notes.  I would now like to merge the changes back into vCenter and overwrite any the descriptions within vCenter but my code is erroring out:

    Import-Csv "c:\output\notes.csv" | % { Set-VM $_.VMName -Notes $_.Note -Confirm:$false}

    Any ideas?



  • 2.  RE: Updating Notes field from a csv

    Posted Jan 19, 2015 10:04 PM

    You need to pass a VM object to Set-VM:

    Import-Csv "c:\output\notes.csv" | % { Get-VM $_.VMName | Set-VM  -Notes $_.Note -Confirm:$false}



  • 3.  RE: Updating Notes field from a csv

    Posted Jan 20, 2015 01:11 AM

    Getting closer...  It seems to be saying that there are no contents in the file, but the fields are populated:



  • 4.  RE: Updating Notes field from a csv
    Best Answer

    Posted Jan 20, 2015 01:35 AM

    Well, the field in your CSV is "Name", not "VMName".

    So try:

    Import-Csv "c:\output\notes.csv" | % { Get-VM $_.Name | Set-VM  -Notes $_.Note -Confirm:$false}



  • 5.  RE: Updating Notes field from a csv

    Posted Jan 20, 2015 01:51 AM

    Sorry, very new to scripting, $_.Note was also wrong and should have been $_.Notes, after that it worked.

    Import-Csv "c:\output\notes.csv" | % { Get-VM $_.Name | Set-VM  -Notes $_.Notes -Confirm:$false}

    Awesome, thanks for your help!