Skip to content

Instantly share code, notes, and snippets.

@imtrinity94
Created May 17, 2023 17:26
Show Gist options
  • Save imtrinity94/1194757c5b79fbb09ca9588fd333ef9f to your computer and use it in GitHub Desktop.
Save imtrinity94/1194757c5b79fbb09ca9588fd333ef9f to your computer and use it in GitHub Desktop.
vRO JavaScript script to Get All vCenter Virtual Machines with No Tags
var arrAllVMs = VcPlugin.getAllVirtualMachines(null, "");
System.log("Total VMs in vCenter: "+arrAllVMs.length);
var client = endpoint.client();
// Set up a dynamic ID for querying
var objId = new com_vmware_vapi_std_dynamic__ID();
var arrVMsWithNoTags = [];
// set up connections for tag associations, tags, and tag categories
var tagging = new com_vmware_cis_tagging_tag__association(client);
var tagMgr = new com_vmware_cis_tagging_tag(client);
var catMgr = new com_vmware_cis_tagging_category(client);
for(var i = 0; i < arrAllVMs.length; i++){
var vm = arrAllVMs[i];
objId.id = vm.id;
objId.type = vm.vimType;
var tagIdList = tagging.list_attached_tags(objId); //returns the ID of each tag
if(tagIdList.length == 0) {
System.log(vm.name +" has no tags.");
arrVMsWithNoTags.push(vm);
}
}
System.log("Total VMs with no tags: "+arrVMsWithNoTags.length);
return arrVMsWithNoTags;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment