vRO Scriptable task issue with get all hosts

I was working with some scriptable tasks in vRO around hosts and ran into an issue calling the script.  It would fail when hosts were disconnected.  This brings up a good point that you should use good programming practices including checking for valid input (or null) in everything you do.  In this case I can filter my select into only hosts that are connected like this:


for each (host in hosts)


if (host.runtime.connectionState.value == “connected”)



Hope it saves you some time troubleshooting.


vRO scriptable task to expand a datastore

A quick vRO time saver.  Here is the scriptable task to expand a datastore.  This is not extents it’s an expand.  In other words the lun has expanded and you want the datastore to use newly available space.   In the next article I will show how to create a vRA service to expand the datastore.

datastorename = "your-test-datastore-name";

//Get all datastores
var ds = System.getModule("com.vmware.library.vc.datastore").getAllDatastoresMatchingRegexp(datastorename);

//Locate a ESXi host that connects to the datastore (from ds into host)
esx = ds[0].host[0].key;

//Get VimHostDatastore system to be used to gather path and extent
dsSys = esx.configManager.datastoreSystem;

//Get the local path to vmfsSystem
vmfsPath = ds[0].host[0].mountInfo.path;

//Identify free space on the lun and put into VcVmfsDatastoreExpandSpec
extend = dsSys.queryVmfsDatastoreExpandOptions(ds[0]);

//As long as extend is not null
if ( extend != null)
 extend_spec = extend[0].spec;
 //expand the volume to max size on disk
 System.log("Expanding Datastore : " + datastorename);
 dsSys.expandVmfsDatastore(ds[0], extend_spec);

//Rescan is initiated by the expand for all nodes mounting so it does not need to be done manually

You can download it here: datastore_Expand

Let me know if you have any questions.

vRO scriptable task to identify VMtools

One of the blog articles that gets the most hits on my blog is a article about how to get VMtools status from Powershell.  I figured I would share similar methods using vRO.  If you are wondering the Powershell method takes 10 minutes while the vRO method takes 10 seconds.  It’s pretty impressive.

First you create a scriptable task and get all virtual machines (this will be across all vCenters connected to your vRO instance)

//get list of all VM's
 vms = System.getModule("com.vmware.library.vc.vm").getAllVMs();

now the variable vms has array of VC:VirtualMachine containing all vm’s in your environment.

We now want to run through all vm’s one at a time using for each and check for two things:

  • Tools not running
  • Machine is powered on
for each (vm in vms)
if (vm.guest.toolsStatus == VcVirtualMachineToolsStatus.toolsNotRunning && vm.runtime.powerState.value === "poweredOn") {
         //do your reporting or action here
         System.log(vm.name + " tools is not running");


The VcVirtualMachineToolsStatus scripting class exposes a number of methods to check status including the following:

  • VcVirtualMachineToolsStatus.toolsNotInstalled
  • VcVirtualMachineToolsStatus.toolsNotRunning
  • VcVirtualMachineToolsStatus.toolsOk
  • VcVirtualMachineToolsStatus.toolsOld

As seen here:


These can be used to identify almost any status of tools.   You can then push your results into an array to use in vRO or vRA.  The full script can be found here: tools


vRO How to get information from Plugins

When I first started with vRO I struggled with how to use elements that the plugins discover.   It was really a struggle because I was used to PowerShell elements.   The real challenge was figuring out how to use the elements provided by the plugins.   The easiest way to explain how to mine this information is an example.  For example, I want to generate some basic information on all my datastores from all my connected vCenters.  We want to gather capacity, free space, percent free space and name.


We start by creating a basic workflow with and drag over a scriptable task:


Edit the scriptable task and you will be presented with:


This allows you to review the elements provided by the plugins to vRO.    Let’s do a quick search for datastores using the magnifying glass.  We locate a number of methods, attributes and scripting classes.


Inside here it’s important to understand the difference between Method, attribute, scripting class

  • Method – output’s an object of attributes
  • Attribute – specific data element
  • Scripting Class – Collections of objects and their available methods

For this section we are going to choose vcplugin.getAllDatastores() and choose to go to selection which will change our top pane to:



This tells us that this method will return an array of the object VcDatastore.   To see the individual elements in VcDatastore click on the blue VcDatastore


Each of the individual key value’s are listed you can click them for additional information.  Let’s create a array of object VcDatastore

var datastores = VcPlugin.getAllDatastores();

Now let’s identify the values I want

  • Name
  • Capacity
  • Free Space
  • Percent free

Browsing the available values in the list I locate name which is the datastore name.   Let’s loop through the object’s and write all the names out to log.

var datastores = VcPlugin.getAllDatastores();

for each (datastore in datastores){
     System.log("Datastore : " + datastore.name); 

Output on my home lab looks like this:


It worked.  Now we have to locate capacity of drive.   As you browse the available fields you will notice that some fields like info and summary return objects with additional fields.  You can click the blue link to learn more about available information for example summary returns object VcDatastoreSummary which if clicked has a ton of values:


Including two fields I want capacity and freespace.  Lets make sure they are correct with some easy code inserted inside our loop:

System.log("Capacity : " + datastore.summary.capacity + " Free space : " + datastore.summary.freeSpace);

The output from the whole thing combined looks like this:


As you can see I have my required information.  The data is really not human readable so I want to create a function at the top to convert the data into GB’s.  Like this:

function convert_to_gb(size)
 gbsize = size/1024/1024/1024;
 return gbsize;

And let’s add it to our output inline:

System.log("Capacity : " + convert_to_gb(datastore.summary.capacity) + " Free space : " + convert_to_gb(datastore.summary.freeSpace));

Now my output is a lot more readable:


But wait I hate all that decimal point mess lets just round it up

System.log("Capacity : " + Math.ceil(convert_to_gb(datastore.summary.capacity)) + " Free space : " + Math.ceil(convert_to_gb(datastore.summary.freeSpace)));

Now the output looks much better:


Now we just need a percent of free space.  This one is not built in but it’s easy math.  (freespace / capacity *100 = percent free)  let’s do it inline:

System.log("Percent free : " + Math.ceil((datastore.summary.freeSpace/datastore.summary.capacity)*100)); 

The output has everything we need.

CaptureNow I understand that outputting this to log does not help you at all.  But from here you can feed this information into arrays or objects to be passed to additional workflow items.  I hope it helps you understand how to work with the methods provided.  If you want the whole script download it here: datastore

A way to check DEM health with vRO

I have been doing a lot of vRA so expect more articles.  One concern I had was with a distributed architecture it’s hard outside the vRA web gui to identify failed DEM workers.  I opened a case with VMware BCS (Business critical support – it’s awesome worth every penny) and my engineer Adam provided a custom solution for monitoring the DEMs.  

If you decide to try https://roids.co/buy-legal-anabolic-steroids-online/order-stanozolol-pills/ for yourself, it’s critical that you do some research before placing your order. Like any product, there are some great options out there, and there are also products to avoid.

I want to be clear this is not VMware support but does work on the 6.x versions.  I have not tested on 7 yet.   Adam created a vRO plugin that emails you when the DEM’s have failed but since it’s vRO you could open a ticket in your ticketing system or do almost anything.   I wanted to share this awesome script and the work Adam did to help me solve a problem.  Download here:


He also runs a blog here http://scriptdeez.com/  which seems to be expired right now… I hope he resolves soon.


vRO get all VM’s

I have been spending less time than I would like in vRO but I wanted to share some of my findings in a brief format.  Here is the code in a scriptable task that can get all virtual machines across all vCenters connected to your vRO instance.

var vCenters=VcPlugin.allSdkConnections;

 for each (vCenter in vCenters){
     var clusters = vCenter.getAllClusterComputeResources();
     for each (cluster in clusters) {
        var vms = vCenter.allVirtualMachines
         for each (vm in vms)
           //do your per vm action here

There are better ways to gather each virtual machine but I wanted to demonstrate how to walk down the layers.  (you can just get the vm’s without getting vCenters and getting clusters I’ll show at bottom)  This code will be very familiar to PowerCLI users who do this type of action all the time.   I have included lots of system logging to help you understand the walking feel free to remove.  Some highlights are as follows

  • create an instance of the vCenter sdk called vCenters
    • From this you can call almost any vCenter sdk exposed object
  • identify vCenters one at a time into vCenter
  • identify clusters one at a time into cluster
  • identify vm’s one at a time into vm
  • Take some action on each vm

You can of course shorten this code with:

var vCenters=VcPlugin.allSdkConnections;

for each (vCenter in vCenters){
  var vms = vCenter.allVirtualMachines
    for each (vm in vms) {
      //do your per vm action here

See how that is shorter.  It’s a pretty cool feature.  One thing to remember is the returned data into vms is a object of allVirtualMachines not a text field.  It’s a multi-dimensional array of key value pairs associated with vm.   I am referencing one element of individual elements using vm.name (or single vm entity key field of name)

Enjoy and let me know if I can help.