Option Explicit
Dim WMIService
Dim VM
Dim VMManagementService
Dim VMSystemSettingData
Dim VMName
Dim NewVMName
Dim Result
'Setup variables for the VM we are looking for, and the new name
VMName = "Windows Server 2003"
NewVMName = "Windows Server 2003 - new"
'Get an instance of the WMI Service in the virtualization namespace.
Set WMIService = GetObject("winmgmts:\\.\root\virtualization")
'Get a VMManagementService object
Set VMManagementService = WMIService.ExecQuery("SELECT * FROM Msvm_VirtualSystemManagementService").ItemIndex(0)
'Get the VM object that we want to modify
Set VM = (WMIService.ExecQuery("SELECT * FROM Msvm_ComputerSystem WHERE ElementName='" & VMName & "'")).ItemIndex(0)
'Get the VirtualSystemSettingsData of the VM we want to modify
Set VMSystemSettingData = (VM.Associators_("MSVM_SettingsDefineState", "MSVM_VirtualSystemSettingData")).ItemIndex(0)
'Change the ElementName property
VMSystemSettingData.ElementName = NewVMName
'Update the VM with ModifyVirtualSystem
Result = VMManagementService.ModifyVirtualSystem(VM.Path_.Path, VMSystemSettingData.GetText_(1))