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
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
Microsoft Hyper-V PowerShell Automation
Microsoft Hyper-V PowerShell Automation

Microsoft Hyper-V PowerShell Automation: Manage, automate, and streamline your Hyper-V environment effectively with advanced PowerShell cmdlets

eBook
₹799.99 ₹1965.99
Paperback
₹2457.99
Subscription
Free Trial
Renews at ₹800p/m

What do you get with a Packt Subscription?

Free for first 7 days. ₹800 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing
Table of content icon View table of contents Preview book icon Preview Book

Microsoft Hyper-V PowerShell Automation

Chapter 1. New PowerShell Cmdlets in Hyper-V on Windows Server 2012 R2

The Hyper-V PowerShell module includes several significant features that extend its use, improve its usability, and allow you to control and manage your Hyper-V environment with more granular control.

Various organizations have moved on from Hyper-V (V2) to Hyper-V (V3). In Hyper-V (V2), the Hyper-V management shell was not built-in and the PowerShell module had to be manually installed. In Hyper-V (V3), Microsoft has provided an exhaustive set of cmdlets that can be used to manage and automate all configuration activities of the Hyper-V environment. The cmdlets are executed across the network using Windows Remote Management.

In this chapter, we will cover:

  • The basics of setting up a Hyper-V environment using PowerShell
  • The fundamental concepts of Hyper-V management with the Hyper-V management shell
  • The updated features in Hyper-V

Here is a list of all the new features introduced in Hyper-V in Windows Server 2012 R2. We will be going in depth through the important changes that have come into the Hyper-V PowerShell module with the following features and functions:

  • Shared virtual hard disk
  • Resizing the live virtual hard disk
  • Installing and configuring your Hyper-V environment

Installing and configuring Hyper-V using PowerShell

Before you proceed with the installation and configuration of Hyper-V, there are some prerequisites that need to be taken care of:

  • The user account that is used to install the Hyper-V role should have administrative privileges on the computer
  • There should be enough RAM on the server to run newly created virtual machines

Once the prerequisites have been taken care of, let's start with installing the Hyper-V role:

  1. Open a PowerShell prompt in Run as Administrator mode:
    Installing and configuring Hyper-V using PowerShell
  2. Type the following into the PowerShell prompt to install the Hyper-V role along with the management tools; once the installation is complete, the Hyper-V Server will reboot and the Hyper-V role will be successfully installed:
    Install-WindowsFeature –Name Hyper-V -IncludeManagementTools -Restart
    
  3. Once the server boots up, verify the installation of Hyper-V using the Get-WindowsFeature cmdlet:
    Get-WindowsFeature -Name hyper*
    

    You will be able to see that the Hyper-V role, Hyper-V PowerShell management shell, and the GUI management tools are successfully installed:

    Installing and configuring Hyper-V using PowerShell

Fundamental concepts of Hyper-V management with the Hyper-V management shell

In this section, we will look at some of the fundamental concepts of Hyper-V management with the Hyper-V management shell. Once you get the Hyper-V role installed as per the steps illustrated in the previous section, a PowerShell module to manage your Hyper-V environment will also get installed. Now, perform the following steps:

  1. Open a PowerShell prompt in the Run as Administrator mode.
  2. PowerShell uses cmdlets that are built using a verb-noun naming system (for more details, refer to Learning Windows PowerShell Names at http://technet.microsoft.com/en-us/library/dd315315.aspx). Type the following command into the PowerShell prompt to get a list of all the cmdlets in the Hyper-V PowerShell module:
    Get-Command -Module Hyper-V
    

    Hyper-V in Windows Server 2012 R2 ships with about 178 cmdlets. These cmdlets allow a Hyper-V administrator to handle very simple, basic tasks to advanced ones such as setting up a Hyper-V replica for virtual machine disaster recovery.

  3. To get the count of all the available Hyper-V cmdlets, you can type the following command in PowerShell:
    Get-Command -Module Hyper-V | Measure-Object
    

    The Hyper-V PowerShell cmdlets follow a very simple approach and are very user friendly. The cmdlet name itself indirectly communicates with the Hyper-V administrator about its functionality. The following screenshot shows the output of the Get command:

    Fundamental concepts of Hyper-V management with the Hyper-V management shell

    For example, in the following screenshot, the Remove-VMSwitch cmdlet itself says that it's used to delete a previously created virtual machine switch:

    Fundamental concepts of Hyper-V management with the Hyper-V management shell
  4. If the administrator is still not sure about the task that can be performed by the cmdlet, he or she can get help with detailed examples using the Get-Help cmdlet. To get help on the cmdlet type, type the cmdlet name in the prescribed format. To make sure that the latest version of help files are installed on the server, run the Update-Help cmdlet before executing the following cmdlet:
    Get-Help <Hyper-V cmdlet> -Full
    

    The following screenshot is an example of the Get-Help cmdlet:

    Fundamental concepts of Hyper-V management with the Hyper-V management shell

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.

Left arrow icon Right arrow icon

Description

This book is great for administrators who are new to automating Hyper-V administration tasks using PowerShell. If you are familiar with the PowerShell command line and have some experience with the Windows Server, this book is perfect for you.

Who is this book for?

This book is great for administrators who are new to automating Hyper-V administration tasks using PowerShell. If you are familiar with the PowerShell command line and have some experience with the Windows Server, this book is perfect for you.

What you will learn

  • Understand and optimize the new features of HyperV on Windows Server 2012 R2
  • Install and configure your HyperV environment on a Windows Server environment using PowerShell
  • Extract information about HyperV hosts and the associated virtual machines
  • Create, delete, start, and stop virtual machines and configure their properties
  • Utilize HyperV PowerShell module cmdlets to create reusable PowerShell scripts
  • Integrate your HyperV environment for enterpriselevel management using SCVMM to create and manage private clouds
  • Troubleshoot your HyperV environment with PowerShell and custom scripts

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Jan 29, 2015
Length: 124 pages
Edition : 1st
Language : English
ISBN-13 : 9781784391539
Vendor :
Microsoft
Tools :

What do you get with a Packt Subscription?

Free for first 7 days. ₹800 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing

Product Details

Publication date : Jan 29, 2015
Length: 124 pages
Edition : 1st
Language : English
ISBN-13 : 9781784391539
Vendor :
Microsoft
Tools :

Packt Subscriptions

See our plans and pricing
Modal Close icon
₹800 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
₹4500 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just ₹400 each
Feature tick icon Exclusive print discounts
₹5000 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just ₹400 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total 10,204.97
Active Directory with PowerShell
₹3649.99
Microsoft Hyper-V PowerShell Automation
₹2457.99
Hyper-V Network Virtualization Cookbook
₹4096.99
Total 10,204.97 Stars icon

Table of Contents

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

Customer reviews

Rating distribution
Full star icon Full star icon Full star icon Full star icon Half star icon 4.8
(4 Ratings)
5 star 75%
4 star 25%
3 star 0%
2 star 0%
1 star 0%
Rafael Bernardes May 09, 2015
Full star icon Full star icon Full star icon Full star icon Full star icon 5
I'm MVP (Microsoft Most Valuable Professional) in Cluster, and constantly work with some automation in powershell. This book is a great reference source for that is beginning to work with Hyper-V and want to automate manual processes. Or even for those who already have some knowledge and have consultations on how to work with the powershell + Hyper-V.As always, Packt produces great books and I recommend it. Always carry on my Kindle;)
Amazon Verified review Amazon
Michael Apr 23, 2015
Full star icon Full star icon Full star icon Full star icon Full star icon 5
I will call myself a PowerUser of PowerShell, but also this book showed my some new stuff.The Book is focused on PowerShell about HyperV and the Automation of it. Also the finest Details has been covered and explained very simple and clearly.I realy like this book and can recommend it.
Amazon Verified review Amazon
Jack May 05, 2015
Full star icon Full star icon Full star icon Full star icon Full star icon 5
As a novice PowerShell user I think this book will provide even the beginners of PowerShell a very good starting point. Great tips and clear explanations this book will provide you with the necessary steps and information to manage a Hyper-V environment. Loads of tips and screenshots to make it more clear to the reader.Great book to have on your digital shelve for administrating your Hyper-V environment. A must have for IT admins :).
Amazon Verified review Amazon
Richard M. Hicks May 19, 2015
Full star icon Full star icon Full star icon Full star icon Empty star icon 4
PowerShell and Hyper-V. You won't find two technologies that need each other more than these. In fact, it seems as if PowerShell was created for Hyper-V! I use both technologies on a regular basis, but I wouldn't claim to be an expert in either so I decided to have a look at this title. The main focus is on Hyper-V in Windows Server 2012 R2, as it should be. There's no point in running Hyper-V on an earlier operating system. The book provides details on the creation and management of virtual machines that any systems administrator can benefit from. This includes, creating and managing snapshots, virtual hard disk management, live migration, and virtual networking. The book also touches on the topic of System Center Virtual Machine Manager (SCVMM) and how to create scripts to ease management and implement automation. Definitely a good read. I'll caution you that some of the commands aren't written in text, but rather shown in a graphic. If you're reading this on a smaller Kindle they can be very difficult to see. Recommend using a large Kindle, tablet, or buying the print edition instead.
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

What is included in a Packt subscription? Chevron down icon Chevron up icon

A subscription provides you with full access to view all Packt and licnesed content online, this includes exclusive access to Early Access titles. Depending on the tier chosen you can also earn credits and discounts to use for owning content

How can I cancel my subscription? Chevron down icon Chevron up icon

To cancel your subscription with us simply go to the account page - found in the top right of the page or at https://subscription.packtpub.com/my-account/subscription - From here you will see the ‘cancel subscription’ button in the grey box with your subscription information in.

What are credits? Chevron down icon Chevron up icon

Credits can be earned from reading 40 section of any title within the payment cycle - a month starting from the day of subscription payment. You also earn a Credit every month if you subscribe to our annual or 18 month plans. Credits can be used to buy books DRM free, the same way that you would pay for a book. Your credits can be found in the subscription homepage - subscription.packtpub.com - clicking on ‘the my’ library dropdown and selecting ‘credits’.

What happens if an Early Access Course is cancelled? Chevron down icon Chevron up icon

Projects are rarely cancelled, but sometimes it's unavoidable. If an Early Access course is cancelled or excessively delayed, you can exchange your purchase for another course. For further details, please contact us here.

Where can I send feedback about an Early Access title? Chevron down icon Chevron up icon

If you have any feedback about the product you're reading, or Early Access in general, then please fill out a contact form here and we'll make sure the feedback gets to the right team. 

Can I download the code files for Early Access titles? Chevron down icon Chevron up icon

We try to ensure that all books in Early Access have code available to use, download, and fork on GitHub. This helps us be more agile in the development of the book, and helps keep the often changing code base of new versions and new technologies as up to date as possible. Unfortunately, however, there will be rare cases when it is not possible for us to have downloadable code samples available until publication.

When we publish the book, the code files will also be available to download from the Packt website.

How accurate is the publication date? Chevron down icon Chevron up icon

The publication date is as accurate as we can be at any point in the project. Unfortunately, delays can happen. Often those delays are out of our control, such as changes to the technology code base or delays in the tech release. We do our best to give you an accurate estimate of the publication date at any given time, and as more chapters are delivered, the more accurate the delivery date will become.

How will I know when new chapters are ready? Chevron down icon Chevron up icon

We'll let you know every time there has been an update to a course that you've bought in Early Access. You'll get an email to let you know there has been a new chapter, or a change to a previous chapter. The new chapters are automatically added to your account, so you can also check back there any time you're ready and download or read them online.

I am a Packt subscriber, do I get Early Access? Chevron down icon Chevron up icon

Yes, all Early Access content is fully available through your subscription. You will need to have a paid for or active trial subscription in order to access all titles.

How is Early Access delivered? Chevron down icon Chevron up icon

Early Access is currently only available as a PDF or through our online reader. As we make changes or add new chapters, the files in your Packt account will be updated so you can download them again or view them online immediately.

How do I buy Early Access content? Chevron down icon Chevron up icon

Early Access is a way of us getting our content to you quicker, but the method of buying the Early Access course is still the same. Just find the course you want to buy, go through the check-out steps, and you’ll get a confirmation email from us with information and a link to the relevant Early Access courses.

What is Early Access? Chevron down icon Chevron up icon

Keeping up to date with the latest technology is difficult; new versions, new frameworks, new techniques. This feature gives you a head-start to our content, as it's being created. With Early Access you'll receive each chapter as it's written, and get regular updates throughout the product's development, as well as the final course as soon as it's ready.We created Early Access as a means of giving you the information you need, as soon as it's available. As we go through the process of developing a course, 99% of it can be ready but we can't publish until that last 1% falls in to place. Early Access helps to unlock the potential of our content early, to help you start your learning when you need it most. You not only get access to every chapter as it's delivered, edited, and updated, but you'll also get the finalized, DRM-free product to download in any format you want when it's published. As a member of Packt, you'll also be eligible for our exclusive offers, including a free course every day, and discounts on new and popular titles.