Question

Using Hyper-V manager (connected to a 2012 R2 core Hyper-V server) I can export a VM and then import that exported VM with a new ID (and rename it afterwards).

I am trying to achieve the same via powershell but this seems not possible or I am overlooking something.

So I have an export and want that export be imported (and registered in place).

Export:

Export-VM -ComputerName $someserver -Name $somevm -Path $exportpath

Import:

Import-VM -ComputerName $someserver -GenerateNewId -Register -Path $pathtoexportedvm_xmlfile

I cannot get this to work. I get vague error messages like:

Parameter set cannot be resolved using the specified named parameters.

I tried to do -Copy instead of -Register which resulted in this error:

Import-VM : Not found

I also tried to leave out -Register but that did not work either.

In the Hyper-V Manager I can point to the folder of the export and select 'generate new id' and then the export is imported. How can I do the same via powershell?

Regards, Rob

Was it helpful?

Solution 2

The solution to this problem is that all three paths have to be specified: -VirtualMachinePath -VhdDestinationPath -SnapshotFilePath

The documentation does not say this nor the error messages.

OTHER TIPS

First, run Update-Help -Force from an Administrator PowerShell prompt. After that, use Get-Help -Name Import-VM to determine the required parameters.

Background

PowerShell advanced functions can have multiple "parameter sets." This allows different logical paths to be followed as part of one command name, depending on which parameters are specified. Based on the parameters that you are specifying, PowerShell is unable to determine which parameter set to use.

For example, consider the help documentation for Invoke-Command. Each of the contiguous "paragraphs" from the docs shows a different parameter set for Invoke-Command. Depending on which parameters you specify, PowerShell will utilize a different parameter set, and follow the appropriate logic.

Invoke-Command Help

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top