I recently created an environment that had a VRA XaaS to apply a security tag to individual virtual machines. I wanted to share the code I wrote to speed up your adoption. In this case we have a scriptable task to do the work. We have one parameter:
![](https://i2.wp.com/blog.jgriffiths.org/wp-content/uploads/2018/12/1.png?fit=1024%2C136)
We have two attributes:
![](https://i0.wp.com/blog.jgriffiths.org/wp-content/uploads/2018/12/2.png?fit=1024%2C138)
Here is the code:
![](https://i2.wp.com/blog.jgriffiths.org/wp-content/uploads/2018/12/3.png?fit=1024%2C566)
Here is the code for cut and paste usage:
//name = ‘dev-214’;
vms = VcPlugin.getAllVirtualMachines();
for each (vm in vms) {
if (vm.Name == name) {
System.log(“VM name: ” + vm.name + ” MOID: ” + vm.id);
machineMOID = vm.id;
}
}
// Apply the tag
NSXSecurityTagManager.applySecurityTagOnVMs(connection, machineMOID, tag);