• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 370
  • Last Modified:

Import Hyper-V VM back onto a Host via Powershell?

Hello all,

Steve Whitcher showed me a great simple Powershell command to Export a VM directly from a host onto a NAS.  Export-VM -Name [VMNAME] -path \\NAS\SHARE.

This helped me get around what appears (according to my perhaps incorrect understanding) to be an outstanding issue in what user and host computer accounts Hyper-V Manager evokes to gain access to the network share (apparently)...although setting the everyone user full access on the NAS (NTFS and Share level) did not solve this problem...

"An error occurred while attempting to export the virtual machine. Failed to create export directory.  Failed to create export directory with error 'General access denied error' (0x80070005)"

Anyway, so until either I can get my head around the actual cause of the error, or MS releases a fix for Hyper-V Manager that invokes the export/import process as a the domain admin account I am using, I was wondering if someone could provide me with another simple Powershell command that can be run from the host?  One that allows me to import virtual machines back onto the host from the NAS, without wiping out existing files on the host as well as making sure the whole VM file structure is on a single data store.  No fancy (lol), separate data stores for different elements of the files that comprise the VM :-)

I tried the Hyper-V Manage GUI (which I run on a server separate from the Hyper-v server hosts) and although it could see the VM folders, it could not see the files inside (again residing on the NAS) and as such had no targets to import from.  I of course tried leaving it on the top level folder to do the import, and it threw an error saying it could not find the virtual machines to import from location...

Thanks for the help and insight.
0
CnicNV
Asked:
CnicNV
  • 3
  • 2
1 Solution
 
VB ITSSpecialist ConsultantCommented:
"An error occurred while attempting to export the virtual machine. Failed to create export directory.  Failed to create export directory with error 'General access denied error' (0x80070005)"
This is because the Computer account for the Hyper-V host doesn't have the necessary Share and NTFS permissions on the NAS share. This Microsoft article outlines the steps required to granted the Hyper-V host's computer account access at the Share and NTFS level on Windows machines: http://support.microsoft.com/en-us/kb/2008849

The problem here is that your NAS doesn't run Windows so the chances of it being able to grant a Domain Computer account access at the share and NTFS levels are slim.

You can try the below manual steps as an alternative method to move the VMs off your NAS and onto your Hyper-V host, although there is some reconfiguration of the VM involved:

- Note down the network configuration of the VM (IP address, default gateway, DNS servers, etc.)
- Shut down the VM
- Right click on the VM in the Hyper-V Manager console and note down its configuration (amount of virtual processors, memory, network adapter, etc.)
- Rename the VM in Hyper-V Manager to something like SERVER-OLD
- Locate the VHD file for the above virtual machine on the NAS then copy it to the Hyper-V host (to somewhere like C:\VHDs)
- Create a new virtual machine with the same specs
- Choose the Use an existing virtual hard disk option and navigate to the VHD file you copied to the host from the above step
- Complete the wizard then turn on the VM when done
- Log in and reconfigure the NIC using the configuration noted down earlier

Hope this helps.
0
 
VB ITSSpecialist ConsultantCommented:
Just had another thought. If your NAS supports iSCSI then you can look at connecting the NAS to the Hyper-V host over iSCSI, then perform the VM exports and imports that way.
0
 
CnicNVAuthor Commented:
This is good info, thanks a lot.  Longer term, I will definitely be investigating these options  Before I close this question off, would you know of a powershell command that I can run from the host that would import any virtual machines back on to it?  IE the reverse of this command...
Export-VM -Name [VMNAME] -path \\NAS\SHARE

Thanks again.
0
 
VB ITSSpecialist ConsultantCommented:
You should be able to simply use the Import-VM command, providing your Hyper-V host is running Server 2012 and onwards. More info on the Import-VM command can be found here: https://technet.microsoft.com/en-us/library/hh848495.aspx
0
 
CnicNVAuthor Commented:
Ok thanks a lot VB ITS :-)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now