Always look at the required parameters of a command:
PARAMETERS
-CustomAttribute <CustomAttribute>
Specifies the custom attribute whose annotation you want to change.
Required? true
-Entity <InventoryItem[]>
Specifies the entities to which the new annotation value applies.
Required? true
-Server <VIServer[]>
Specifies the vCenter Server systems on which you want to run the cmdlet. If no value is provided or $null value is passed to this parameter, the command runs on the defau
lt servers. For more information about default servers, see the description of Connect-VIServer.
Required? false
-Value <String>
Specifies a new value for the annotation.
Required? true
-Confirm [<SwitchParameter>]
If the value is $true, indicates that the cmdlet asks for confirmation before running. If the value is $false, the cmdlet runs without asking for user confirmation.
Required? false
-WhatIf [<SwitchParameter>]
Indicates that the cmdlet is run only to display the changes that would be made and actually no objects are modified.
Required? false
<CommonParameters>
This cmdlet supports the common parameters: Verbose, Debug,
ErrorAction, ErrorVariable, WarningAction, WarningVariable,
OutBuffer, PipelineVariable, and OutVariable. For more information, see
about_CommonParameters (https://go.microsoft.com/fwlink/?LinkID=113216).
Those cannot be omitted.
Possibly you first have to read them and than pipe them to be removed.
So something like Get-Annotation -Entity (required) | Set-Annotation -Value ''
Or maybe use the CustomAttribute cmdlt's if needed.
Get-CustomAttribute
Remove-CustomAttribute or Set-CustomAttribute
Original Message:
Sent: Oct 20, 2024 06:32 PM
From: Ami01
Subject: Clearing all custom attributes and annotations on my VMs
Hi @LucD,
Thanks for this.
I am getting this error:
Set-Annotation : The input object cannot be bound to any parameters for the command either because the command does not take pipeline input or the input and its properties do not match any of the
parameters that take pipeline input.
At line:6 char:1
+ Set-Annotation -Value '' -Confirm:$false
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (NBU_POLICY_ENABLED:scsi0-2:PSObject) [Set-Annotation], ParameterBindingException
+ FullyQualifiedErrorId : InputObjectNotBound,VMware.VimAutomation.ViCore.Cmdlets.Commands.SetAnnotation
Original Message:
Sent: Oct 18, 2024 05:54 AM
From: LucD
Subject: Clearing all custom attributes and annotations on my VMs
Try with.
It assumes the CSV contains a column named VMName.
$ca = Get-CustomAttribute -Name 'CAName' -TargetType VirtualMachineImport-Csv -Path '.\vmnames.csv' -PipelineVariable row |Foreach-Object -Process { Get-VM -Name $row.VMName | Get-Annotation -CustomAttribute $ca | Set-Annotation -Value '' -Confirm:$false}
------------------------------
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Original Message:
Sent: Oct 17, 2024 04:56 PM
From: Ami01
Subject: Clearing all custom attributes and annotations on my VMs
Hi @LucD
I know this is an old post but this is very helpful!
I'd like to remove a value of a custom attribute on multiple VMs from a CSV file. Can you help me with this please? TIA
Original Message:
Sent: Aug 13, 2018 08:26 AM
From: LucD
Subject: Clearing all custom attributes and annotations on my VMs
If you define a Custom Attribute of the type VirtualMachine, each VM will have this Custom Attribute.
You have 2 options:
- remove the Custom Attribute globally (see my previous reply)
- set the Custom Attribute value to blank on a specific VM. Like this
$ca = Get-CustomAttribute -Name Test2 -TargetType VirtualMachine
Get-VM -Name MyVM | Get-Annotation -CustomAttribute $ca | Set-Annotation -Value '' -Confirm:$false
You can not remove a Custom Attribute on a single VM, only change its value.