Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
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
$13.98 $19.99
Paperback
$32.99
Subscription
Free Trial
Renews at $19.99p/m

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Table of content icon View table of contents Preview book icon Preview Book

Microsoft Hyper-V PowerShell Automation

Chapter 2. Managing Your Hyper-V Virtual Infrastructure

Managing Hyper-V virtual infrastructure components is an integral part of a Hyper-V administrator's day-to-day activities. Performing these administrative tasks manually is time-consuming and leads to a reduction in productivity; replacing these repetitive tasks with PowerShell leads to better consistency (no typos or execution of incorrect tasks). This also helps a senior administrator delegate these tasks to other members in the team and audit the tasks performed by those individuals so that he or she can concentrate on other important tasks that lead to a better learning curve and improve the creative ability of the administrator to automate complex tasks.

In the current chapter and Chapter 3, Managing Your Hyper-V Virtual Machines, we will explore the various PowerShell cmdlets in depth that can be used to automate these set of repetitive tasks performed by an administrator.

In this chapter, we will cover the following...

Extracting information about Hyper-V hosts and the associated virtual machines

Microsoft offers the ability to extract information related to the Hyper-V infrastructure using PowerShell. It is now possible to perform virtual machine management from the command line using the Hyper-V PowerShell module.

Let's start exploring the ways in which you can extract information related to a Hyper-V host.

For Hyper-V deployments that are not clustered, host-level information can be extracted by the Get-VMHost cmdlet:

Get-VMHost | fl *

Open up a PowerShell prompt in your Windows Server 2012 R2 Hyper-V server in the Run as Administrator mode and type the following cmdlets:

  • Get-ClusterNode: This cmdlet shows details of the nodes in the cluster
  • Get-ClusterNode | select @{l='ComputerName';e={$_.name}}: This cmdlet shows the names of the Hyper-V hosts in the cluster
  • Get-VMHost –computername <HVHostName>: This cmdlet shows details of the Hyper-V hosts

Now, by combining all the preceding...

Creating, deleting, starting, and stopping virtual machines

Creating, deleting, starting, or stopping a virtual machine is one of the most repetitive tasks that a Hyper-V administrator needs to perform, but with PowerShell, all these tasks can be scripted and made simpler to execute.

Creating a virtual machine

Creating a virtual machine is relatively simple with PowerShell using the New-VM PowerShell cmdlet. Before you execute the commands to create a VM, let's look at Get-VM, which gives the list of all the VMs that are present on the Hyper-V host cluster. The following command gets the nodes that are part of the Hyper-V cluster. It creates a value by property and name called ComputerName and passes it to the Get-VM cmdlet:

Get-ClusterNode | select @{l='ComputerName';e={$_.name}} | Get-VM

Windows Server 2012 R2 introduced the concept of generation 1 and generation 2 virtual machines, and the same can be created with PowerShell:

Then, we use the New-VM cmdlet to create virtual...

Configuring properties on virtual machines

Configuring properties on virtual machines can be done using PowerShell cmdlets that have the Set verb in them. To get a list of all the PowerShell cmdlets that can be used to set a virtual machine's properties, type command shown in the following screenshot, in the PowerShell prompt:

Configuring properties on virtual machines

As you can see in the preceding screenshot, there are a number of properties that can be set for the virtual machine, including the BIOS, DVD drive, virtual machine memory, and also network adapter properties. Also, there is a Set-VMHost cmdlet that allows you to set some of the properties related to the Hyper-V host. Let's go through these cmdlets one by one.

Type the following cmdlet in the PowerShell prompt to change the automatic stop action of all the VMs running on both nodes of the Hyper-V cluster:

Get-ClusterNode | select @{l='ComputerName';e={$_.name}} | % {Get-VM -ComputerName $_.computername | Set-VM -AutomaticStopAction shutdown }

Note...

Summary

In this chapter, we covered important cmdlets related to configuring and extracting properties about virtual machines and their associated Hyper-V hosts. In the next chapter, we will cover the other set of relevant cmdlets that can be used to automate Hyper-V administrative tasks in detail.

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 : 9781784392208
Vendor :
Microsoft
Tools :

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Product Details

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

Packt Subscriptions

See our plans and pricing
Modal Close icon
$19.99 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
$199.99 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 $5 each
Feature tick icon Exclusive print discounts
$279.99 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 $5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total $ 136.97
Active Directory with PowerShell
$48.99
Microsoft Hyper-V PowerShell Automation
$32.99
Hyper-V Network Virtualization Cookbook
$54.99
Total $ 136.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

How do I buy and download an eBook? Chevron down icon Chevron up icon

Where there is an eBook version of a title available, you can buy it from the book details for that title. Add either the standalone eBook or the eBook and print book bundle to your shopping cart. Your eBook will show in your cart as a product on its own. After completing checkout and payment in the normal way, you will receive your receipt on the screen containing a link to a personalised PDF download file. This link will remain active for 30 days. You can download backup copies of the file by logging in to your account at any time.

If you already have Adobe reader installed, then clicking on the link will download and open the PDF file directly. If you don't, then save the PDF file on your machine and download the Reader to view it.

Please Note: Packt eBooks are non-returnable and non-refundable.

Packt eBook and Licensing When you buy an eBook from Packt Publishing, completing your purchase means you accept the terms of our licence agreement. Please read the full text of the agreement. In it we have tried to balance the need for the ebook to be usable for you the reader with our needs to protect the rights of us as Publishers and of our authors. In summary, the agreement says:

  • You may make copies of your eBook for your own use onto any machine
  • You may not pass copies of the eBook on to anyone else
How can I make a purchase on your website? Chevron down icon Chevron up icon

If you want to purchase a video course, eBook or Bundle (Print+eBook) please follow below steps:

  1. Register on our website using your email address and the password.
  2. Search for the title by name or ISBN using the search option.
  3. Select the title you want to purchase.
  4. Choose the format you wish to purchase the title in; if you order the Print Book, you get a free eBook copy of the same title. 
  5. Proceed with the checkout process (payment to be made using Credit Card, Debit Cart, or PayPal)
Where can I access support around an eBook? Chevron down icon Chevron up icon
  • If you experience a problem with using or installing Adobe Reader, the contact Adobe directly.
  • To view the errata for the book, see www.packtpub.com/support and view the pages for the title you have.
  • To view your account details or to download a new copy of the book go to www.packtpub.com/account
  • To contact us directly if a problem is not resolved, use www.packtpub.com/contact-us
What eBook formats do Packt support? Chevron down icon Chevron up icon

Our eBooks are currently available in a variety of formats such as PDF and ePubs. In the future, this may well change with trends and development in technology, but please note that our PDFs are not Adobe eBook Reader format, which has greater restrictions on security.

You will need to use Adobe Reader v9 or later in order to read Packt's PDF eBooks.

What are the benefits of eBooks? Chevron down icon Chevron up icon
  • You can get the information you need immediately
  • You can easily take them with you on a laptop
  • You can download them an unlimited number of times
  • You can print them out
  • They are copy-paste enabled
  • They are searchable
  • There is no password protection
  • They are lower price than print
  • They save resources and space
What is an eBook? Chevron down icon Chevron up icon

Packt eBooks are a complete electronic version of the print edition, available in PDF and ePub formats. Every piece of content down to the page numbering is the same. Because we save the costs of printing and shipping the book to you, we are able to offer eBooks at a lower cost than print editions.

When you have purchased an eBook, simply login to your account and click on the link in Your Download Area. We recommend you saving the file to your hard drive before opening it.

For optimal viewing of our eBooks, we recommend you download and install the free Adobe Reader version 9.