jlenag
Enthusiast
Enthusiast

Workflow to shut down certain VMs on a host

Jump to solution

Brand new to Orchestrator here, so be gentle please.....

I'm trying to build a workflow to put an ESX host in MM so that we can schedule this to be done.  The main problem i'm having is due to 3 host agent VMs that run on all my hosts.  1 of them needs to be shut down first, followed by the other 2.  These cannot be migrated and will cause the MM command to error out if they are still powered on at that time.

I tried playing around with how to do this, but I'm having trouble isolating each VM in order to shut it down.  The naming schemes are not the greatest, but are shown below

CVM-%hostname%

GuestSec (1)  -  the number is different on every host

AgentVM (1) - same as above for number

I can make the first one work due to it just being the hostname (which i know), but I can't find a good way to locate the other two for shut down.  Would this be easier to build a PS host and use powerCLI?  I have some experience with that and know it wouldn't be too bad to do, but thought I would ask before I make another run at a PS Host (i failed setup the first time, but w/e).

I would think there would be an easy way to list all the VMs on a host and then search through it since I know the names of what i need.  Any help would be appreciated!

0 Kudos
1 Solution

Accepted Solutions
iiliev
VMware Employee
VMware Employee

Here is a code snippet that enumerates all VMs on a host and prints their names. Its input parameter is the variable host of type VC:HostSystem

var host = ...; // your host of type VC:HostSystem; can be passed as an input to the workflow, or obtained in some other way

var vmsOnHost = host.vm;

for each (var vm in vmsOnHost) {

  System.log("vm found, name: " + vm.name);

}

View solution in original post

0 Kudos
2 Replies
iiliev
VMware Employee
VMware Employee

Here is a code snippet that enumerates all VMs on a host and prints their names. Its input parameter is the variable host of type VC:HostSystem

var host = ...; // your host of type VC:HostSystem; can be passed as an input to the workflow, or obtained in some other way

var vmsOnHost = host.vm;

for each (var vm in vmsOnHost) {

  System.log("vm found, name: " + vm.name);

}

View solution in original post

0 Kudos
jlenag
Enthusiast
Enthusiast

Thank you!  This is what i was missing.  This combined with some array searching did the trick for me. 

0 Kudos