Preserve parameter in Export-VM

Feb 25, 2011 at 2:19 PM

I have been trying desperately to use the -Preserve parameter of Export-VM.  Everytime I try this, the machine files get exported just fine, but when it start to zip the files up it always ends in an error like the one below:

============================================================

Exception calling "NameSpace" with "1" argument(s): "Unspecified error (Excepti
on from HRESULT: 0x80004005 (E_FAIL))"
At C:\Program Files\modules\Hyperv\Helper.ps1:27 char:40
+              $global:shellApp.NameSpace <<<< ($Zippath).CopyHere($File.fullna
me)
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : ComMethodTargetInvocation

Exception calling "NameSpace" with "1" argument(s): "Unspecified error (Excepti
on from HRESULT: 0x80004005 (E_FAIL))"
At C:\Program Files\modules\Hyperv\Helper.ps1:27 char:40
+              $global:shellApp.NameSpace <<<< ($Zippath).CopyHere($File.fullna
me)
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : ComMethodTargetInvocation

========================================================

Has anyone successfully used this functionality that would be willing to share the secret?? Every other function I have tried has worked beautifully (KUDOS to the developers).

Coordinator
Mar 1, 2011 at 12:51 AM

Is this happening on full server, Server-Core , or Hyper-V server ? I'll check this ASAP.

Mar 1, 2011 at 3:19 PM

Hyper-V server in a cluster. I tried running script (commandlet) on same host as virtual machine and from another cluster node. No matter how I tried it, I ended up with a zip file with a size of zero and errors showing.

Paul Stocks | Server Engineer | Technology Services Department

Analysts International Corporation | 3601 West 76th Street, Suite 500| Minneapolis, MN 55435
DID: (952) 838-2998 | IPTel: 810-2998 | FAX: (952) 838-3150
| pstocks@analysts.com | www.analysts.com

Description: Email signature logo ...IT Professionals On Demand

From: jamesone [email removed]
Sent: Monday, February 28, 2011 6:51 PM
To: Stocks, Paul
Subject: Re: Preserve parameter in Export-VM [PSHyperv:247570]

From: jamesone

Is this happening on full server, Server-Core , or Hyper-V server ? I'll check this ASAP.

Coordinator
Mar 10, 2011 at 7:25 PM

OK I've checked this properly now. The bad news is that this depends on the windows shell , hence the problem with  $global:shellApp.NameSpace

The workround would be  as follows.

If you search in the file VM.PS1 This line is the one which creates the zip file.

  Add-ZIPContent "$path\$($vm.elementname)\importFiles.zip" "$path\$($vm.elementname)\config.xml","$path\$($vm.elementname)\virtual machines"

You can replace it with whatever command line zip / rar / whatever format tool you choose.  You'll probably need 2 commands, In the old days of Free command line PKZIP it would have been something like

PKZIP.EXE   "$path\$($vm.elementname)\importFiles.zip"    -a "$path\$($vm.elementname)\config.xml" 

PKZIP.EXE   "$path\$($vm.elementname)\importFiles.zip"    -a ""$path\$($vm.elementname)\virtual machines"

Powershell will munge the bits inside the quotes and pass the executable a zip file name, the -a (add) switch and the File Path or Folder Path.

There is a second line for backing up snapshot information

if (Get-ChildItem "$path\$($vm.elementname)\snapshots") {Add-ZIPContent "$path\$($vm.elementname)\importFiles.zip" "$path\$($vm.elementname)\snapshots"}

Again change Add-zipcontent to use your command line tool  , the first parameter is the zip file name and the second is what is being added to it.

Hope that helps

James.