Hi,
I'm using some commands to get and set annotation fields for a while without issues.
In the meantime vCenter was upgraded to version 7.0.3 and Set-Annotation doesn't work as before. I'm not sure if the syntax changed or what I'm doing wrong.
- reading the list of VMs from a text file (Linux):
$vmList = Get-Content t.txt
- get the list of VMs with the annotation field is working fine
foreach ($vmName in $vmList) {Get-Annotation -Entity $vmName -CustomAttribute "Backup"}
AnnotatedEntity Name Value
--------------- ---- -----
vm1 Backup yes
vm2 Backup no
- Set-Annotation doesn't work as before:
foreach ($vmName in $vmList) {Set-Annotation -Entity $vmName -CustomAttribute "Backup" -value no-backup}
Set-Annotation: 2/8/2023 6:58:49 AM Set-Annotation Could not find annotation with name 'Backup'.
Set-Annotation: 2/8/2023 6:58:49 AM Set-Annotation Could not find annotation with name 'Backup'.
Any idea please?
Does it work like this?
$ca = Get-CustomAttribute -Name 'Backup'
$vmList = Get-Content t.txt
foreach ($vmName in $vmList) {
Get-VM -Name $vmName |
Set-Annotation -CustomAttribute $ca -value 'no-backup'
}
I suspect the OBN feature might have an issue.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Does it work like this?
$ca = Get-CustomAttribute -Name 'Backup'
$vmList = Get-Content t.txt
foreach ($vmName in $vmList) {
Get-VM -Name $vmName |
Set-Annotation -CustomAttribute $ca -value 'no-backup'
}
I suspect the OBN feature might have an issue.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks it's working fine like that!
The difference was made by $ca variable. It's working even with the following syntax:
foreach ($vmName in $vmList) {Set-Annotation -Entity $vmName -CustomAttribute $ca -value no-backup}
Using the name of an object instead of the object itself is handled by a feature in PowerCLI that is called OBN (Object By Name).
I noticed as well that sometimes this doesn't work as expected.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference