VMware Cloud Community
Robert_BE
Contributor
Contributor

exclude vm's

i have schedule workflow for reset all vm's one time in week,

i take all vms from "vm folder" but i want to exclude vms from list of "array of virtualMachine".

is it possible?

0 Kudos
5 Replies
admin
Immortal
Immortal

Hi Robert_BE,

both are arrays, so you have to compare them and if the names are not eqal you can push them in a new array as base for your reset. Here is how:

Comparing two arrays in Javascript - Stack Overflow

Best regards

Christian

0 Kudos
Robert_BE
Contributor
Contributor

Cristian tank you for your response,

i dont compare between 2 arrays becuse i get all vm from folder and after i use "for each" command,

so i want to check if one VM belong to list of vms.

0 Kudos
vThinkBeyondVM
VMware Employee
VMware Employee

You can create ArrayList containing "MOR" (Managed Object reference) of each VM. Take each MOR one by one out & if it is of the Vm that you want to exclude, just straightway skip any operation on that VM.

Let me know if you need any help.


----------------------------------------------------------------
Thanks & Regards
Vikas, VCP70, MCTS on AD, SCJP6.0, VCF, vSphere with Tanzu specialist.
https://vThinkBeyondVM.com/about
-----------------------------------------------------------------
Disclaimer: Any views or opinions expressed here are strictly my own. I am solely responsible for all content published here. Content published here is not read, reviewed or approved in advance by VMware and does not necessarily represent or reflect the views or opinions of VMware.

0 Kudos
Robert_BE
Contributor
Contributor

Hi,

"VMS" is aray of all Virtual machine,

"exlude" is array of 3 vm's,

I mean something like this:

for each var vm in vms {

if (??? != ????) {

Task=system.getModule("com.vmware.library.vc.vm.power").resetVM(vm)

}

so what is the command instead (??? !=???)  for check if vm belog to "exclude" ?

0 Kudos
Kagome
Enthusiast
Enthusiast

a really simple Solution would be:

https://www.vmware.com/support/orchestrator/doc/vco_vsphere55_api/html/VcVirtualMachine.html

i hope every VM in your environment has a unique name...

//we go through each VM

for(var i in VMS)

{

     //each new VM is per default not excluded

     var isExcluded = false;

     // check against exclude array

     for(var j in exclude)

     {

          if(VMS[i].name == exclude[j].name)

          {

               isExcluded = true;

          }

     }

     //check if VM is now excluded

     if(isExcluded)

     {

          System.debug(VMS[i].name +" is excluded from restart");

     }else

     {

          System.getModule("com.vmware.library.vc.vm.power").resetVM(VMS[i])

     }    

}

out of my brain .. not tested.

0 Kudos