Script to add VMs to Virtual Server
Want to register multiple existing VMs (or just one for that matter) to Virtual Server a bit quicker than going through the GUI? I wrote a little script that will register existing .vmc files. It might come in handy.
The script can be used in two ways: by dubble-clicking it in the directory where your .vmc files are located, or by dragging a.vmc file on to of it. (or passing it as a command-line parameter).
'Registers all VMC files in the current directory, except when one or more .VMC file
' are given as a argument; in that case those VMC will be registered.
Dim objFSO, objVS
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objVS = CreateObject("VirtualServer.Application")
On Error resume next
If Wscript.Arguments.Count <> 0 Then
'Register the VMC files given as parameters
For i = 0 to Wscript.Arguments.Count – 1
Err.Clear
If Right(Wscript.Arguments(i),4) = ".vmc" then
Set objVM = objVS.RegisterVirtualMachine("", Wscript.Arguments(i))
If Err.Number <> 0 Then
WScript.Echo "Registration of ‘" & Wscript.Arguments(i) & " NOT successful: " & Err.Description
Else
WScript.Echo "Registration of ‘" & Wscript.Arguments(i) & " successful"
End If
End If
Next
Else
'Register the VMC files in the current directory
'Obtain an folder object instance for the current directory
Dim objFolder
Set objFolder = objFSO.GetFolder(".")
Dim objFile
For Each objFile in objFolder.Files
On Error resume next
If Right(objFile.Name,4) = ".vmc" then
Set objVM = objVS.RegisterVirtualMachine("", objFile)
If Err.Number <> 0 Then
WScript.Echo "Registration of ‘" & objFile.Name & " NOT successful: " & Err.Description
Else
WScript.Echo "Registration of ‘" & objFile.Name & " successful"
End If
end if
Next
End If