Partilhar via


Automating VSDM via scripts

Sample scripts are bundled with VSDM in its installation folder (by default C:\Program Files\VSDM\samples). It is recommended that you have some understanding of the VSDM solution before continuing to read this article.

Option

Explicit
Dim server
Dim wsh
Dim inet
Dim newVM
Dim vmName
Dim template
Dim network
Dim vmID
Dim rand

' This variable points to your VSDM server root
' e.g.: https://yourserver:81

server = "https://myserver"

' These variables define your VM name and template used

vmName = "AutomationTest" ' Your machine name
template = "xp-pro" ' Machine template to base on
network = 2 ' 2 = Internal Network (but subject to change)

' Random number to avoid collision when running this sample

rand = Now
rand = Replace(rand, "/", "-")
rand = Replace(rand, ":", "-")

Set wsh = CreateObject("WScript.Shell")
Set inet = CreateObject("InternetExplorer.Application")

' Building your VM name

vmID = wsh.ExpandEnvironmentStrings("%USERNAME%." & template & "." & vmName & " " & rand)

' URL to create a new VM

newVM = server & "/vm_ctrl.asp?action=add&name=" & vmID &_
   "&template=" & template &_
   "&types=" & template &_
   "&nettype=" & network

'WScript.Echo "Create <[" & newVM & "]>"

' Call the Internet object to perform the action

WScript.Echo "Performing action. Please wait..."
inet.Navigate newVM

' Wait the request to complete

while inet.Busy
WScript.Echo "Waiting to complete..."
   WScript.Sleep 1000
wend

WScript.Echo

"Request completed"