Download VMware Scripting API

Transcript
Using Sample VmCOM Programs
switch (vm.ExecutionState) {
case vmExecutionState_On:
return "ON";
break;
case vmExecutionState_Off:
return "OFF";
break;
case vmExecutionState_Suspended:
return "SUSPENDED";
break;
case vmExecutionState_Stuck:
return "STUCK";
break;
default:
return "UNKNOWN";
break;
}
}
The source for the sample program 1 accompanying Windows Script File is in the SampleScripts
folder in the VmCOM Scripting API directory.
You can also find it on the VMware Web site, saved with a .TXT extension for online viewing, at
www.vmware.com/support/developer/scripting-API/doc/sample1.wsf.txt.
Note: If you are using Microsoft® Internet Explorer as your browser, select View > Source to view the
file. Alternately, right-click this link and download this file.
<job id="Sample1">
<reference object="VmCOM.VmCtl" />
<script language="JScript" src="sample1.js" />
</job>
VBScript Sample Program 2
This VBScript sample program 2 provides similar functionality to sample program 1. It also connects
to the local server and lists all registered virtual machines. If a virtual machine is in the stuck state, the
pending question is displayed.
In addition, sample program 2 also illustrates how to handle a virtual machine that is waiting for input
to a question (that is, the virtual machine is in the vmExecutionState_Stuck state). For
example, if a virtual machine is configured with an undoable disk and a redo log is found, this script
automatically keeps the redo log during a shutdown operation or appends the redo log during a
power-on operation.
Note: The script’s question-answering code is highly dependent on the version of your server
product and the language used in the question. This script can malfunction with a newer version of
30
www.vmware.com