Book Image

Microsoft Hyper-V PowerShell Automation

By : Vinith Menon
Book Image

Microsoft Hyper-V PowerShell Automation

By: Vinith Menon

Overview of this book

Table of Contents (13 chapters)
Microsoft Hyper-V PowerShell Automation
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Creating reusable scripts for virtual machine live migration


Reusable scripts help the Hyper-V administrator to automate various mundane tasks. Let's explore ways to automate one of the most commonly used virtual machine tasks. To do this, let's look at a script that can be used to automate the live migration of virtual machines across various Hyper-V hosts in a cluster.

Similar to the previous script, let's break this script into various components to understand its execution step by step. Also, in the scripting technique illustrated as follows, we will be using the concept of PowerShell workflows to migrate the virtual machines across the Hyper-V host cluster live in a parallel manner and not a sequential one:

workflow Move-LiveVM

{

param(
[Parameter(Mandatory)]
[string]$SourceHyperVhost,
[Parameter(Mandatory)]
[string]$DestinationHyperVhost,
[Parameter(Mandatory)]
[string]$ClusterName

)

Using the preceding piece of code, we created a PowerShell workflow called Move-LiveVM, which gets...