
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
3 comments
And in case you want to unregister them again:
‘Unregisters VMs that have the same name as the files in the current directory.
‘No questions asked!
Dim objFSO, objVS
Set objFSO = CreateObject(“Scripting.FileSystemObject”)
Set objVS = CreateObject(“VirtualServer.Application”)
‘Obtain an folder object instance for a particular 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
strVMName = Left(objFile.Name, Len(objFile.Name)-4)
Set objVM = objVS.FindVirtualMachine(strVMName)
objVS.UnregisterVirtualMachine(objVM)
If Err.Number <> 0 Then
WScript.Echo “UnRegistration of ‘” & strVMName & ” NOT successful: ” & Err.Description
Else
WScript.Echo “UnRegistration of ‘” & strVMName & ” successful”
End If
End if
Next
robp
Very handy script.
Thank you!
Fareed
Fantastic script! Both of them! Saved ma a ton of time on course 5115A and 5116A! Thanks!!!
Marin