VMware Cloud Community
TheVMinator
Expert
Expert
Jump to solution

vRO Workflow - List VMs by OS

What is involved in creating a workflow to list all VMs by OS type, list the names of the VM, the OS type, and then email the results?

0 Kudos
1 Solution

Accepted Solutions
iiliev
VMware Employee
VMware Employee
Jump to solution

It's pretty straightforward.

The first step is to get all virtual machines; the second is to sort/group the list by OS guest type, and the last step is to construct the body of the mail (as plain text or HTML) containing the information from the machines. Here is some sample code (without the code to send the email):

// Step 1: Get all virtual machines

var allVMs = VcPlugin.getAllVirtualMachines();

function guestId(a) {

  var aid = null;

  if (a.summary != null && a.summary.config != null) aid = a.summary.config.guestId;

  if (aid == null && a.config != null) aid = a.config.guestId;

  if (aid == null && a.guest != null) aid = a.guest.guestId;

  if (aid == null) aid = "";

  return aid;

}

// Step 2: Sort/group virtual machines by OS guest type

allVMs.sort(function(a,b) {

  return guestId(a).localeCompare(guestId(b));

});

// Step 3: Send as mail using EmailMessage scripting class

var content = "";

for each (var vm in allVMs) {

  System.log(vm.name + " -- " + guestId(vm) + " -- " + vm.summary.config.guestFullName);

  content += vm.name + " -- " + guestId(vm) + " -- " + vm.summary.config.guestFullName + " \n";

}

The interesting part is how to retrieve OS info - it can be done either via summary.config property, via config property, or via guest property of the VM (some of these properties can be null in some cases, eg. if there is no VMware Tools installed on the VM).

View solution in original post

0 Kudos
2 Replies
iiliev
VMware Employee
VMware Employee
Jump to solution

It's pretty straightforward.

The first step is to get all virtual machines; the second is to sort/group the list by OS guest type, and the last step is to construct the body of the mail (as plain text or HTML) containing the information from the machines. Here is some sample code (without the code to send the email):

// Step 1: Get all virtual machines

var allVMs = VcPlugin.getAllVirtualMachines();

function guestId(a) {

  var aid = null;

  if (a.summary != null && a.summary.config != null) aid = a.summary.config.guestId;

  if (aid == null && a.config != null) aid = a.config.guestId;

  if (aid == null && a.guest != null) aid = a.guest.guestId;

  if (aid == null) aid = "";

  return aid;

}

// Step 2: Sort/group virtual machines by OS guest type

allVMs.sort(function(a,b) {

  return guestId(a).localeCompare(guestId(b));

});

// Step 3: Send as mail using EmailMessage scripting class

var content = "";

for each (var vm in allVMs) {

  System.log(vm.name + " -- " + guestId(vm) + " -- " + vm.summary.config.guestFullName);

  content += vm.name + " -- " + guestId(vm) + " -- " + vm.summary.config.guestFullName + " \n";

}

The interesting part is how to retrieve OS info - it can be done either via summary.config property, via config property, or via guest property of the VM (some of these properties can be null in some cases, eg. if there is no VMware Tools installed on the VM).

0 Kudos
TheVMinator
Expert
Expert
Jump to solution

ok great - thanks!

0 Kudos