--Begin Code--
'======
'
' NAME: p2v.vbs
'
' AUTHOR: Stagner , Harley
' DATE : 10/30/2007
'
' COMMENT: This script will convert a machine to a VM based on the parameters in "C:\p2v\p2v.xml"
' An email is then sent to the admin responsible for checking on the newly converted VM.
'
'======
'***********************************************************************
'*****************************Header Section*******************************
'***********************************************************************
Option Explicit
Dim objShell, objScriptExec, objWMIService, objEmail
Dim strStartTime, strFinishTime, strComputer
Dim colProcesses
Dim i
'**********************************************************************
'*******************************Reference /Worker Section*******************
'**********************************************************************
'* In this section I define the Start Time for p2vtool.exe and set up the objects *
'* required to run p2vtool.exe and monitor the p2vtool.exe process. The finish time for *
'* p2vtool.exe is defined after the p2vtool.exe process terminates. *
'**********************************************************************
strStartTime = Now
strComputer = "."
Set objShell = CreateObject("WScript.Shell")
Set objScriptExec = objShell.Exec ("C:\Program Files\VMware\" _
& "VMware Converter\p2vTool.exe --import --source C:\p2v\p2v.xml")
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colProcesses = objWMIService.ExecQuery _
("Select * from Win32_Process Where Name = 'p2vTool.exe'")
i = colProcesses.Count
Do Until i = 0 'This loop is required to get the correct finish time for the email message.
Set colProcesses = objWMIService.ExecQuery _
("Select * from Win32_Process Where Name = 'p2vTool.exe'")
i = colProcesses.Count
Loop
strFinishTime = Now
'**************************************************************************
'**********************************Output Section*****************************
'**************************************************************************
'* In this section, I email the administrator responsible for the VM migration to let *
'* or her know that the migration is complete so that he or she can do any necessary *
'* VM cleanup afterwards. *
'**************************************************************************
Set objEmail = CreateObject("CDO.Message")
objEmail.From = ""
objEmail.To = ""
objEmail.Subject = "VM Migration Completed"
objEmail.Textbody = "Your VM Migration started at: " & strStartTime & "." & vbCRLF & vbCRLF _
& "Your VM Migration finished at: " & strFinishTime & "." & vbCRLF & vbCRLF _
& "Please log into the Virtual Infrastructure Client to remove any unnecessary hardware " & _
"and ensure that the newly migrated VM is on the correct network."
objEmail.Configuration.Fields.Item _
(" = 2
objEmail.Configuration.Fields.Item _
(" = _
"your_smtp_server"
objEmail.Configuration.Fields.Item _
(" = 25
objEmail.Configuration.Fields.Update
objEmail.Send
--End Code--