VMware Cloud Community
MRoushdy
Hot Shot
Hot Shot
Jump to solution

Updating VM Notes using a CSV file

Hello,

I need to update all of the VM Notes (about 300 VMs), and I have the info in a CSV file, two columns are in the file, one for VM name, the other for the Note, no column heads in present.

vEXPERT - VCAP-DCV - Blog: arabitnetwork.com | YouTube: youtube.com/c/MohamedRoushdy
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

You didn't include a sample entry from your CSV file, but I assume the two columns are separated by a comma.

Then you could do

Get-Content -Path vm-notes-update.csv | ConvertFrom-Csv -Header VMName,Notes | %{

    Get-VM -Name $_.VMName | Set-VM -Notes $_.Notes -Confirm:$false

}


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

0 Kudos
4 Replies
LucD
Leadership
Leadership
Jump to solution

You didn't include a sample entry from your CSV file, but I assume the two columns are separated by a comma.

Then you could do

Get-Content -Path vm-notes-update.csv | ConvertFrom-Csv -Header VMName,Notes | %{

    Get-VM -Name $_.VMName | Set-VM -Notes $_.Notes -Confirm:$false

}


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
MRoushdy
Hot Shot
Hot Shot
Jump to solution

Hello again, the data is in two columns, do you want me to add a comma in between? , or concatenate the data of two columns into one and add a comma in between?

vEXPERT - VCAP-DCV - Blog: arabitnetwork.com | YouTube: youtube.com/c/MohamedRoushdy
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Can you just check if the following is reading the two columns on each row correctly.

Get-Content -Path vm-notes-update.csv | ConvertFrom-Csv -Header VMName,Notes

You can do a quick test by placing a couple of the lines into an inline string construct.

Something like this

$test = @"

vm1,new note

vm2,new note2

"@

$test | ConvertFrom-Csv -Header VMName,Notes

For the earlier script to work this should return two properties for each line.

Like this

VMName Notes   

------ -----   

vm1    new note

vm2    new note2


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
MRoushdy
Hot Shot
Hot Shot
Jump to solution

Worked as smooth as a knife in a piece of butter Smiley Happy

Thanks,

vEXPERT - VCAP-DCV - Blog: arabitnetwork.com | YouTube: youtube.com/c/MohamedRoushdy
0 Kudos