Remove Custom Attribute script from Virtual Machines annotation


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.

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.

# 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.

get-vm -name vmname | Get-Annotation

Replace custom attribute - 1

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

Replace custom attribute - 2