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?
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}
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}
Getting closer... It seems to be saying that there are no contents in the file, but the fields are populated:
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}
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!