VMware Cloud Community
Hans1bad
Contributor
Contributor

Add Comments to Notes during Cloning

We are currently deploying 20+ VMs at a time based on a spreadsheet. We would like to read from a field "Notes" and update the description as the new VMs are spun up. The code "set-vm $vmname -Description $note" seems to only work when the vm already exists. We would like to update the notes when the VM is being created. Any help would be appreciated. Thanks.

#CLONE TASK

write-output "The VM being cloned is " $vmname

$task = $vmmorview.CloneVM_Task($targetview.MoRef,$vmname, $vmcSpec )

$note = (Get-VM $vmname).Description

$note += " appended text" + $vmnotes

set-vm $vmname -Description $note -Confirm:$false

Reply
0 Kudos
4 Replies
LucD
Leadership
Leadership

In your $vmcSpec object you can use the property $vmcSpec.config.annotation.

That is the Notes field that you see in the VIC.

The naming conventions used by the different VMW teams is not making this any easier. Smiley Wink


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

Reply
0 Kudos
Hans1bad
Contributor
Contributor

Now I know where to look, but I can't figure out how to set the value.

from

I can't find the Config.Annotation

Do I have to set it like this

$vmcSpec.Customization.Config.Annotation = $Notes

I am a bit stuck...

#CLONE TASK

write-output "The VM being cloned is " $vmname

$task = $vmmorview.CloneVM_Task($targetview.MoRef,$vmname, $vmcSpec )

Reply
0 Kudos
LucD
Leadership
Leadership

I assume the $vmcSpec is created somewhere before you make the call to the CloneVM_Task method.

In there you have to first allocate a VirtualMachineConfigSpec object (if that is not already done in the script) and assign it to the $vmcSpec.config property.

And then you can set the value of the annotation property.

...
$vmcSpec.config = New-Object VMware.Vim.VirtualMachineConfigSpec
$vmcSpec.config.annotation = "whatever textyou want in the notes field"
....
#CLONE TASK
write-output "The VM being cloned is " $vmname
$task = $vmmorview.CloneVM_Task($targetview.MoRef,$vmname, $vmcSpec )
....


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

Reply
0 Kudos
Hans1bad
Contributor
Contributor

That is the part I was missing. Everything is now working and the earth has started rotating again.

Thank you.

Reply
0 Kudos