Scripting VMware Power Tools: Automating Virtual Infrastructure Administration

Appendix A: All Scripts and Program Source

In this appendix, we ve compiled the key scripts cited in this book. You can use this appendix as a quick reference point to review these scripts.

Scripts from Chapter 3

The following demonstrates the instantiation of the VmConnectParams object in VBScript and how to set the properties listed earlier.

Set objConnParams = CreateObject("VmCOM.VmConnectParams")objConnParams.hostname = "esxserver1"objConnParams.username = "adminuser1"objConnParams.password = "password1"

The following continues from the previous code example, adding the instantiation of the VmServerCtl object and connecting to the host using the previously defined VmConnectParams object.

Set objVMServer = CreateObject("VmCOM.VmServerCtl")objVMServer.Connect objConnParamsobjVMList = objVMServer.RegisteredVmNamesfor vmIndex = 1 to objVMList.Count     WScript.Echo VM.objVMList(vmCounter)     vmCounter = vmCounter + 1next

The following demonstrates how you can ensure that no floppy drives are left connected to the VM. After connecting to the ESX host and retrieving a VmCollection of all registered VMs, the script connects to each VM individually, checks the connection status of the floppy device, and disconnects it accordingly.

' Set parameters used to connect to the ESX Server.Set objConnParams = CreateObject("VmCOM.VmConnectParams")objConnParams.hostname = "esxserver1 "objConnParams.username = "adminuser1"objConnParams.password = "password1"' Establish connection with ESX hostSet objVMServer = CreateObject("VmCOM.VmServerCtl")objVMServer.Connect objConnParams' Obtain list of registered VMs on hostSet objVMList = objVMServer.RegisteredVmNames' Step through list of VMs and connect to each one' individually. Disconnect floppy drive, if connectedFor each ConfigFile in objVMList     Set objVM = CreateObject("VmCOM.VmCtl")     objVM.Connect objConnParams, ConfigFile     vmDevice = "floppy0"   ...

UNLIMITED FREE
ACCESS
TO THE WORLD'S BEST IDEAS

SUBMIT
Already a GlobalSpec user? Log in.

This is embarrasing...

An error occurred while processing the form. Please try again in a few minutes.

Customize Your GlobalSpec Experience

Category: Console Consolidation Systems
Finish!
Privacy Policy

This is embarrasing...

An error occurred while processing the form. Please try again in a few minutes.