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.
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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:

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.
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.
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.
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:

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
CnicNVAuthor Commented:
Ok thanks a lot VB ITS :-)
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.