VMware Cloud Community
mtrohde
Enthusiast
Enthusiast

Clearing all custom attributes and annotations on my VMs

A previous VMWare admin had set annotations on all of our VMs.  No one has maintained these annotations since then and the info is now out of date and confusing.  So what I want to do is clear all of these out.  Can someone comeup with a powercli script that would delete all custom attributes and annotations for VMs in my vCenter?

Regards,

Michael

8 Replies
LucD
Leadership
Leadership

Would this do the trick?

Get-CustomAttribute | Remove-CustomAttribute -Confirm:$false

Get-VM | Set-Annotation -Notes '' -Confirm:$false


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

Reply
0 Kudos
Eraser2005
Contributor
Contributor

Hi,

the command

Get-VM | Set-Annotation -Notes '' -Confirm:$false

isn't working on our Systems. we have vCenter 6.5.

Best regards

Reply
0 Kudos
LucD
Leadership
Leadership

Try with the following (in the more recent PowerCLI versions, the Set-Annotation cmdlet doesn't have a Notes parameter)

Get-VM | Set-VM -Notes '' -Confirm:$false


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

Reply
0 Kudos
Eraser2005
Contributor
Contributor

Okay, this works fine but i have a other problem.

We are using Citrix to deploy virtual machine on the esx.

Citrix create a custom Attribute with the Name "XdConfig" and the value "XdProvisioned=true" on the vm.

i want to know, how delete the custom Attribute on the virtual machine?

Reply
0 Kudos
LucD
Leadership
Leadership

Can you try with

Get-CustomAttribute -Name XdConfig -TargetType VirtualMachine |

Remove-CustomAttribute -Confirm:$false


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

Reply
0 Kudos
Eraser2005
Contributor
Contributor

Hi Luc,

thank you very much for the quick Response.

But i wont to delete the global Attribute on the Host/vCenter.

There is a custom Attribute on the virtual machine.

If i use the powershell command:

(get-vm -Name "NameOfTheVM").ExtensionData.AvailableField

i become the value:

Key                     : 408

Name                    : XdConfig

Type                    : string

ManagedObjectType       : VirtualMachine

FieldDefPrivileges      :

FieldInstancePrivileges :

DynamicType             :

DynamicProperty         :

How to delete this custom field on the vm?

Thank for your Response.

Reply
0 Kudos
LucD
Leadership
Leadership

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.


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

Eraser2005
Contributor
Contributor

Hi Luc,

thank you very much.

This Reply solved my Issue.

Reply
0 Kudos