Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Microsoft Hyper-V PowerShell Automation

You're reading from   Microsoft Hyper-V PowerShell Automation Manage, automate, and streamline your Hyper-V environment effectively with advanced PowerShell cmdlets

Arrow left icon
Product type Paperback
Published in Jan 2015
Publisher
ISBN-13 9781784391539
Length 124 pages
Edition 1st Edition
Tools
Arrow right icon
Author (1):
Arrow left icon
Vinith Menon Vinith Menon
Author Profile Icon Vinith Menon
Vinith Menon
Arrow right icon
View More author details
Toc

Table of Contents (8) Chapters Close

Preface 1. New PowerShell Cmdlets in Hyper-V on Windows Server 2012 R2 FREE CHAPTER 2. Managing Your Hyper-V Virtual Infrastructure 3. Managing Your Hyper-V Virtual Machines 4. Creating Reusable PowerShell Scripts Using Hyper-V PowerShell Module Cmdlets 5. The Next Step – Integration with SCVMM 6. Troubleshooting Hyper-V Environment Issues and Best Practices Using PowerShell Index

Shared virtual hard disks

This new and improved feature in Windows Server 2012 R2 allows an administrator to share a virtual hard disk file (the .vhdx file format) between multiple virtual machines. These .vhdx files can be used as shared storage for a failover cluster created between virtual machines (also known as guest clustering). A shared virtual hard disk allows you to create data disks and witness disks using .vhdx files with some advantages:

  • Shared disks are ideal for SQL database files and file servers
  • Shared disks can be run on generation 1 and generation 2 virtual machines

This new feature allows you to save on storage costs and use the .vhdx files for guest clustering, enabling easier deployment rather than using virtual Fibre Channel or Internet Small Computer System Interface (iSCSI), which are complicated and require storage configuration changes such as zoning and Logic Unit Number (LUN) masking.

In Windows Server 2012 R2, virtual iSCSI disks (both shared and unshared virtual hard disk files) show up as virtual SAS disks when you add an iSCSI hard disk to a virtual machine. Shared virtual hard disks (.vhdx ) files can be placed on Cluster Shared Volumes (CSV) or a Scale-Out File Server cluster

Let's look at the ways you can automate and manage your shared .vhdx guest clustering configuration using PowerShell. In the following example, we will demonstrate how you can create a two-node file server cluster using the shared VHDX feature. After that, let's set up a testing environment within which we can start learning these new features. The steps are as follows:

  1. We will start by creating two virtual machines each with 50 GB OS drives, which contains a sysprep image of Windows Server 2012 R2. Each virtual machine will have 4 GB RAM and four virtual CPUs.

    Note

    D:\vhd\base_1.vhdx and D:\vhd\base_2.vhdx are already existing VHDX files with sysprepped image of Windows Server 2012 R2.

    The following code is used to create two virtual machines:

    New-VM –Name "Fileserver_VM1" –MemoryStartupBytes 4GB –NewVHDPath d:\vhd\base_1.vhdx -NewVHDSizeBytes 50GB
    
    New-VM –Name "Fileserver_VM2" –MemoryStartupBytes 4GB –NewVHDPath d:\vhd\base_2.vhdx -NewVHDSizeBytes 50GB
    
  2. Next, we will install the file server role and configure a failover cluster on both the virtual machines using PowerShell.

    Note

    You need to enable PowerShell remoting on both the file servers and also have them joined to a domain.

    The following is the code:

    Install-WindowsFeature -computername Fileserver_VM1 File-Services, FS-FileServer, Failover-Clustering
    
    Install-WindowsFeature -computername Fileserver_VM1 RSAT-Clustering –IncludeAllSubFeature
    
    Install-WindowsFeature -computername Fileserver_VM2 File-Services, FS-FileServer, Failover-Clustering
    
    Install-WindowsFeature -computername Fileserver_VM2 RSAT-Clustering -IncludeAllSubFeature
    
  3. Once we have the virtual machines created and the file server and failover clustering features installed, we will create the failover cluster as per Microsoft's best practices using the following set of cmdlets:
    New-Cluster -Name Cluster1 -Node FileServer_VM1, FileServer_VM2 -StaticAddress 10.0.0.59 -NoStorage –Verbose
    

    You will need to choose a name and IP address that fits your organization.

  4. Next, we will create two vhdx files named sharedvhdx_data.vhdx (which will be used as a data disk) and sharedvhdx_quorum.vhdx (which will be used as the quorum or the witness disk). To do this, the following commands need to be run on the Hyper-V cluster:
    New-VHD -Path c:\ClusterStorage\Volume1\sharedvhdx_data.VHDX -Fixed -SizeBytes 10GB
    
    New-VHD -Path c:\ClusterStorage\Volume1\sharedvhdx_quorum.VHDX -Fixed -SizeBytes 1GB
    
  5. Once we have created these virtual hard disk files, we will add them as shared .vhdx files. We will attach these newly created VHDX files to the Fileserver_VM1 and Fileserver_VM2 virtual machines and specify the parameter-shared VHDX files for guest clustering:
    Add-VMHardDiskDrive –VMName Fileserver_VM1 -Path c:\ClusterStorage\Volume1\sharedvhdx_data.VHDX –ShareVirtualDisk
    
    Add-VMHardDiskDrive –VMName Fileserver_VM2 -Path c:\ClusterStorage\Volume1\sharedvhdx_data.VHDX –ShareVirtualDisk
    
  6. Finally, we will be making the disks available online and adding them to the failover cluster using the following command:
    Get-ClusterAvailableDisk | Add-ClusterDisk
    

Once we have executed the preceding set of steps, we will have a highly available file server infrastructure using shared VHD files.

You have been reading a chapter from
Microsoft Hyper-V PowerShell Automation
Published in: Jan 2015
Publisher:
ISBN-13: 9781784391539
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image