VM (on server) shutdown, copy and start script
Home › Forums › Scripting › General Scripting › VM (on server) shutdown, copy and start script
- This topic has 4 replies, 3 voices, and was last updated 9 years, 7 months ago by
Anonymous.
-
AuthorPosts
-
marcopoloMemberJun 14, 2011 at 7:08 am #155061I’m looking to create an automated way to shutdown some of my Virtual Machines on some servers, copy the various files and then startup again.
I’ve come up with this, but it isn’t quite working right. All it seems to be doing is shutting down and restarting.
The command I’m using is:
Cscript test.vbs VMname “E:testVirtual MachinesVMname”
test.vbs
‘Script Begins
On Error Resume Next‘Create Shell Object
Set objShell = CreateObject (“WScript.Shell”)‘Connect to Virtual Server
Set virtualServer = CreateObject(“VirtualServer.Application”)‘Get virtual machine from command-line parameter
set vm = virtualServer.FindVirtualMachine(WScript.Arguments(0))‘shutdown the virtual machine
set shutdownTask = vm.GuestOS.Shutdown‘Loop waiting for task completion
while not shutdownTask.isComplete
WScript.Sleep 1000
wend‘Copy virtual hard disks and undo disks
for each vhd in vm.HardDiskConnections
objShell.Run “%comspec% /c copy ” & chr(34) & vhd.undoHardDisk.file & chr(34) & ” ” & chr(34) & WScript.Arguments(1) & chr(34),1 , True
objShell.Run “%comspec% /c copy ” & chr(34) & vhd.HardDisk.file & chr(34) & ” ” & chr(34) & WScript.Arguments(1) & chr(34),1 , True
next
‘Copy .VMC and .VSV files
objShell.Run “%comspec% /c copy ” & chr(34) & vm.File & chr(34) & ” ” & chr(34) & WScript.Arguments(1) & chr(34),1 , True
objShell.Run “%comspec% /c copy ” & chr(34) & vm.SavedStateFilePath & chr(34) & ” ” & chr(34) & WScript.Arguments(1) & chr(34),1 , True‘Once everything is done – startup the virtual machine
vm.Startup‘Script ends[/CODE]
Any pointers?Thanks,
Mark[CODE]’Script Begins
On Error Resume Next‘Create Shell Object
Set objShell = CreateObject (“WScript.Shell”)‘Connect to Virtual Server
Set virtualServer = CreateObject(“VirtualServer.Application”)‘Get virtual machine from command-line parameter
set vm = virtualServer.FindVirtualMachine(WScript.Arguments(0))‘shutdown the virtual machine
set shutdownTask = vm.GuestOS.Shutdown‘Loop waiting for task completion
while not shutdownTask.isComplete
WScript.Sleep 1000
wend‘Copy virtual hard disks and undo disks
for each vhd in vm.HardDiskConnections
objShell.Run “%comspec% /c copy ” & chr(34) & vhd.undoHardDisk.file & chr(34) & ” ” & chr(34) & WScript.Arguments(1) & chr(34),1 , True
objShell.Run “%comspec% /c copy ” & chr(34) & vhd.HardDisk.file & chr(34) & ” ” & chr(34) & WScript.Arguments(1) & chr(34),1 , True
next
‘Copy .VMC and .VSV files
objShell.Run “%comspec% /c copy ” & chr(34) & vm.File & chr(34) & ” ” & chr(34) & WScript.Arguments(1) & chr(34),1 , True
objShell.Run “%comspec% /c copy ” & chr(34) & vm.SavedStateFilePath & chr(34) & ” ” & chr(34) & WScript.Arguments(1) & chr(34),1 , True‘Once everything is done – startup the virtual machine
vm.Startup‘Script ends[/CODE]
Any pointers?Thanks,
Mark
-
AuthorPosts
You must be logged in to reply to this topic.