Template Script

Image 

Onderstaand script dient als template voor nieuwe scripts zodat er altijd van een basis wordt uitgegaan.

Bron : Simplifying Administration with the wmware Scripting APIs. (WMworld 2006)

' VmCOM Script template
'
' File:             vmcom-template.vbs
'
' Author        Bas Dorland <bas @ dorland.org>
'
' Purpose      Default template for creating VmCOM Scripts
'
' Usage         cscript //nologo vmcome-template.vbs

Option Explicit
On error Resume Next

'— Create ConnectParams object
set cp = createObject("VmCOM.VmConnectParams")

'— Prompt for input
Wscript.StdOut.Write "Please enter the DNS name or ipadres of the ESX server: "
cp.hostname = Wscript.StdIn.Readline
Wscript.StdOut.Write "Please enter the username to connect to the server: "
cp.username = Wscript.StdIn.Readline
Wscript.StdOut.Write "Please enter the users password to connect to the server: "
cp.password = Wscript.StdIn.Readline
cp.port = 0

Wscript.Echo "Attemting to connect to " & cp.hostname & " as " & cp.username & " with " & cp.password & " …"

'— Create the server object
set server = CreateObject ("VmCOM.VmServerCtl")

'— Attempt to connect to the server
Server.Connect cp
If Err.Number <> 0 Then
    WScript.Echo "Could not connect to the server: "& Err.Description
    WScript.Quit
End If

'—INSERT ADDITIONAL CODE HERE

Wscript.Echo "Done!"