VMware Cloud Community
dbutch1976
Hot Shot
Hot Shot
Jump to solution

Updating Notes field from a csv

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?

Untitled.jpg

Reply
0 Kudos
1 Solution

Accepted Solutions
sneddo
Hot Shot
Hot Shot
Jump to solution

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}

View solution in original post

Reply
0 Kudos
4 Replies
sneddo
Hot Shot
Hot Shot
Jump to solution

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}

Reply
0 Kudos
dbutch1976
Hot Shot
Hot Shot
Jump to solution

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

Untitled.jpg

Reply
0 Kudos
sneddo
Hot Shot
Hot Shot
Jump to solution

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}

Reply
0 Kudos
dbutch1976
Hot Shot
Hot Shot
Jump to solution

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!

Untitled.jpg

Reply
0 Kudos