ExportVirtualSystemEx and ImportVirtualSystemEx

Jul 22, 2010 at 5:17 PM

I see that the Import-VM and Export-VM use ImportVirtualSystem and ExportVirtualSystem, respectively.  Are there plans to use the ExportVirtualSystemEx and ImportVirtualSystemEx variants of these?  The Ex versions have a bunch of necessary features, namely, ExportVirtualSystemEx can export VMs with snapshots and ImportVirtualSystemEx can create copies of the source files.

 

Here is the sample of using ExportVirtualSystemEx

$Msvm_VirtualSystemExportSettingDataPath = "\\"+$Server+"\root\virtualization:Msvm_VirtualSystemExportSettingData"
$Msvm_VirtualSystemExportSettingData = ([WmiClass]$Msvm_VirtualSystemExportSettingDataPath).CreateInstance()

$Msvm_VirtualSystemExportSettingData.CopyVmStorage = $true   
$Msvm_VirtualSystemExportSettingData.CopyVmRuntimeInformation = $true   
$Msvm_VirtualSystemExportSettingData.CreateVmExportSubdirectory = $true   

#0 = All snaphots, 1 = No snapshots, 2 = One snapshot
$Msvm_VirtualSystemExportSettingData.CopySnapshotConfiguration = 0
$Msvm_VirtualSystemExportSettingData.SnapshotVirtualSystem = $null
 ...

$VSMgtSvc.ExportVirtualSystemEx($VM.__path,  $path, $Msvm_VirtualSystemExportSettingData)

 

And an example of using ImportVirtualSystemEx (This one is not working quite right yet for me...)

$Msvm_VirtualSystemImportSettingDataPath = "\\"+$Server+"\root\virtualization:Msvm_VirtualSystemImportSettingData"
$Msvm_VirtualSystemImportSettingData  = ([WmiClass]$Msvm_VirtualSystemImportSettingDataPath).CreateInstance()

$Msvm_VirtualSystemImportSettingData.GenerateNewId = $true    
$Msvm_VirtualSystemImportSettingData.CreateCopy = $true 
if($name) {
	$Msvm_VirtualSystemImportSettingData.Name = $name    
}
$Msvm_VirtualSystemImportSettingData.SourceSnapshotDataRoot = $path + "\Snapshots"
$Msvm_VirtualSystemImportSettingData.SourceVhdDataRoot = $path + "\Virtual hard Disks"
$Msvm_VirtualSystemImportSettingData.SourceVmDataRoot = $path + "\Virtual Machines"

if($createCopy) {
	$Msvm_VirtualSystemImportSettingData.TargetSnapshotDataRoot = $targetCopyRootPath + "\Snapshots"
	$Msvm_VirtualSystemImportSettingData.TargetVhdDataRoot = $targetCopyRootPath + "\Virtual hard Disks"
	$Msvm_VirtualSystemImportSettingData.TargetVmDataRoot = $targetCopyRootPath + "\Virtual Machines"
}

$Result=$VSMgtSvc.importVirtualSystemEx($path, $Msvm_VirtualSystemImportSettingData ) 

 

May 31, 2012 at 7:55 PM

Hi murkjohansen,

I am attempting to clone a bunch of VM's by exporting and then importing a Golden VM. I am using the Windows Server 8 DataCenter. I used the importVirtualSystemEx(...) to import an already exported VM.  I cannot seem to be able to display the Msvm_VirtualSystemImportSettingData object that I obtained using the GetVirtualSystemImportSettingData(...). I am pasting the code sample below

$ExpPath = "C:\Sample_Export"

$VMMgmtService = Get-WmiObject -Namespace "root\virtualization" -Class MSVM_VirtualSystemManagementService

$ImportSettings = $VMMgmtService.GetVirtualSystemImportSettingData($ExpPath)

$ImportSettings= $ImportSettings.ImportSettingData

$ImportSettings.GenerateNewId = $TRUE

$ImportSettings.CreateCopy = $TRUE

At this point im getting an error which says that

"Property 'GenerateNewId' cannot be found on this object; make sure it exists and is settable."

"Property 'CreateCopy' cannot be found on this object; make sure it exists and is settable."

Can you please shed some light on where I am going wrong?

Thanks in Advance!

-Regards,

JJ