Wednesday, June 24, 2009

Hyper-V & SCVMM Error: 0x80070057 Import / Export Virtual Machine

Today I tried to import a VM using the Hyper-V mmc console that I exported some time ago to later use. When I tried to do that I got the error:

Hyper-V Manager
A server error occured while attempting to import the virtual machine.
Failed to import the virtual nachine from directory %directorypath%.
Error: One or more arguments are invalid (0x80070057).

The solution to fix this error is to clear the ScopeOfResidence value and you should be able to import the same machine again with no errors.

To do that, go to the the VM path folder, then open the {GUID}.exp file (generally under "drive:\pathtovm\vmname\Virtual Machines\"). Open the .exp file
In this case clear the value for 9c62b993-f3e9-44fc-80e1-f798f8bbe17f :

Save the file and import the machine again.


DONE!

TIP: Suppose that you sysprep a VM and exported that VM to latter use. Now you duplicated that exported VM into 10 VMs (VM01, 02, 03 ...). When you try to import that VM you get this error, what to do?

2 options:

You can correct the ScopeOfResidence value for the original VM (the exported VM) and then duplicate that VM to 10 VMs as you did.

Or

You can correct the ScopeOfResidence value on the first duplicated VM (VM01) and then copy that *.exp file to all other VMs (VM02, 03 ...). Will this cause trouble with duplicated *.exp file names? No as long as you don't use the option "Reuse old virtual machine IDs", because when you import that VM, Hyper-V will change the value of those files to a different {GUID}.xml file.



After solving this one, I went to internet and did a search for a MS KB about this problem, and I found additional information under KB968968 that states this problem for Hyper-V and System Center Virtual Machine Manager (SCVMM) scenarios.

Additionaly they provide a script to use on a Hyper-V server before you import a virtual machine to the Hyper-V server

*****************************************************

Option Explicit

Dim WMIService
Dim VMList
Dim VM
Dim VMSystemGlobalSettingData
Dim VMManagementService
Dim Result

'Get instance of 'virtualization' WMI service on the local computer
Set WMIService = GetObject("winmgmts:\\.\root\virtualization")

'Get a VMManagementService object
Set VMManagementService = WMIService.ExecQuery("SELECT * FROM Msvm_VirtualSystemManagementService").ItemIndex(0)

'Get all the MSVM_ComputerSystem object
Set VMList = WMIService.ExecQuery("SELECT * FROM Msvm_ComputerSystem")

For Each VM In VMList
if VM.Caption = "Virtual Machine" then
Set VMSystemGlobalSettingData = (VM.Associators_("MSVM_ElementSettingData", "Msvm_VirtualSystemGlobalSettingData")).ItemIndex(0)
VMSystemGlobalSettingData.ScopeOfResidence = ""
Result = VMManagementService.ModifyVirtualSystem(VM.Path_.Path, VMSystemGlobalSettingData.GetText_(1))
end if
Next

*****************************************************

No comments:

Post a Comment