Home » Hyper-V » Default File Locations in Hyper-V

Default File Locations in Hyper-V

If you value or enjoy this blog please feel free to donate. I receive no compensation for it and do not sell my endorsements.

Follow me on Twitter

Archives

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Join 2,402 other followers

This post was originally written for the Canadian IT Pro Connection blog, and can be seen there at http://blogs.technet.com/b/canitpro/archive/2012/09/11/default-file-locations-in-hyper-v.aspx.

Note: This article applies equally to the server-side and client-side hypervisor.  Although some scenarios may not apply to older versions, the technical steps apply to all versions of Hyper-V released to date.

A virtual machine in Hyper-V consists of a few files that account for its virtual hardware configuration and the virtual storage (VHD and VHDX files).  By default the virtual machine configuration files are stored in C:\ProgramData\Microsoft\Windows\Hyper-V, and the virtual hard drives are stored in C:\Users\Public\Documents\Hyper-V\Virtual Hard Disks.

One slight improvement in Hyper-V (in Windows Server 2012) is that during the installation process (GUI mode only) it gives you the option of changing these defaults.  However the defaults are still the same as they used to be… on the C drive.

While you can change these file locations on a per-VM basis when you create them, there are several reasons why you might want to change these global default locations within your hosts.

  • If you enable cluster shared volumes (CSVs) then the best practice would be to store your new VMs in the CSV to facilitate live migration or failover.
  • In the client-side hypervisor in Windows 8 installed on a laptop you may want to use an external drive connected to a fast USB port to store your virtual machines.
  • For our demo and lab machines, we find it easier to store the VHD files in the root of the C drive for easier navigation.

Whatever the reason, here is a simple way to make it happen.  Remember, these steps will apply to virtual machines created going forward only, and will not move any pre-existing VMs.

  1. In the global Actions pane of Hyper-V Manager click Hyper-V Settings…
  2. Under Virtual Hard Disks change the location from the default to your desired location.
  3. Under Virtual Machines change the location from the default to your desired location, and click apply.

SNAGHTML38ec90[4]

4.   Click OK to close the Hyper-V Settings page.

PowerShell Tip: I am often asked ‘Can you do this in PowerShell?’  My usual reply is that PowerShell can do almost anything.  So thanks to my #1 PowerShell Resource (PowerShell MVP Sean Kearney) I can provide you with the exact script to accomplish the same task.  This method has the added benefit of working on either local or remote Hyper-V hosts, assuming you have the proper credentials.

  1. Make sure the directories you plan to use are already created.
  2. SET-VMHOST –computername <server> –virtualharddiskpath ‘C:\VHDs’
  3. SET-VMHOST –computername <server> –virtualmachinepath ‘C:\VMs’

By the way, you can also string these two together with the following script:

SET-VMHOST –computername <server> -virtualharddiskpath ‘C:\VHD’ -virtualmachinepath ‘C:\VM’

Now when you create a new virtual machine, the files will be stored where you want them, without having to change them manually.  It’s simple!

About these ads

1 Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Tweet Tweet…

Follow The World According to Mitch on WordPress.com
%d bloggers like this: