---
title: "Remove Custom Attribute script from Virtual Machines annotation"
date: "2015-06-24T14:02:40Z"
tags: ["PowerCLI"]
categories: ["Scripting & Automation", "VMware"]
---

![PowerCLI][1]

In Today post I would like to show you quick method of replacing annotations which quite a lot of people use to store details about Virtual Machines. As usual this short script was created to automate things rather than do it all manually.
<!--more-->
<!--adsense-->
In my company we use annotations to store information about Virtual Machines. I was quite often asked about VMs I deployed three Years ago - like I remember it now 🙂 So to remove information about myself I used following script.
```PowerShell
###
# Purpose        : Replace custom attribute in Virtual Machines
# Created        : 24.06.2015
# Author         : Wojciech Marusiak
# Pre-requisites : none
###
Add-PSSnapin VMware.VimAutomation.Core
If ($globale:DefaultVIServers) {
    Disconnect-VIServer -Server $global:DefaultVIServers -Force
    }
    
$vCenter = Read-Host "Please provide name or IP address of the vCenter Server"
$credentials = get-credential
connect-viserver -server $vCenter -Credential $credentials

$vms = Get-VM | where {(get-annotation -Entity $_ -CustomAttribute Creator).Value -eq "searched phrase"} 
foreach($vm in $vms){
Set-Annotation -Entity $vm -CustomAttribute "Creator" -Value " "
}

Disconnect-VIServer "*" -Confirm:$False
```

In my case I am replacing custom attribute **Creator** with space. If you want to replace another custom attribute you first need to find it.

To show which custom attributes you have run following oneliner.

```PowerShell
get-vm -name vmname | Get-Annotation
```

![Replace custom attribute - 1][2]

Afterwards simply change in line 16 value for -CustomAttribute and in line 18 the one in quotation mark.

![Replace custom attribute - 2][3]

[1]: /images/uploads/2015/06/powercli.webp
[2]: /images/uploads/2015/06/replace-custom-attribute.webp
[3]: /images/uploads/2015/06/replace-custom-attribute-2.webp
