SlideShare a Scribd company logo
1 of 5
Download to read offline
Step-by-Step: Live Migrate Multiple
(Clustered) VMs in One Line of PowerShell Revisited
KeithMayer[1]
24 Feb 2014 9:03 PM
A while back, I wrote an article showing how to Live Migrate Your VMs in One Line of
Powershell[2] between non-clustered Windows Server 2012 Hyper-V hosts using
Shared Nothing Live Migration. Since then, I’ve been asked a few times for how this
type of parallel Live Migration would be performed for highly available virtual machines
between Hyper-V hosts within a cluster.
In this article, we’ll walk through the steps of doing exactly that … via Windows
PowerShell on Windows Server 2012 or 2012 R2[3] or our FREE Hyper-V Server 2012
R2[4] bare-metal, enterprise-grade hypervisor in a clustered configuration.

Wait! Do I need PowerShell to Live Migrate multiple VMs within a
Cluster?
Well, actually … No. You could certainly use the Failover Cluster Manager GUI tool
to select multiple highly available virtual machines, right-click and select Move | Live
Migration …
[5]
[6]

Failover Cluster Manager – Performing Multi-VM Live Migration
But, you may wish to script this process for other reasons … perhaps to efficiently drain
all VM’s from a host as part of a maintenance script that will be performing other tasks.

Can I use the same PowerShell cmdlets for Live Migrating within a
Cluster?
Well, actually … No again. When VMs are made highly available resources within a
cluster, they’re managed as cluster group resources instead of being standalone VM
resources. As a result, we have a different set of Cluster-aware PowerShell cmdlets[7]
that we use when managing these cluster groups. To perform a scripted multi-VM Live
Migration, we’ll be leveraging three of these cmdlets:

Now, let’s see that one line of PowerShell!
Before getting to the point of actually performing the multi-VM Live Migration in a
single PowerShell command line, we first need to setup a few variables to handle the
"what" and "where" of moving these VMs.
First, let’s specify the name of the cluster with which we’ll be working. We’ll store it in
a $clusterName variable.
$clusterName = read-host -Prompt "Cluster name"
Next, we’ll need to select the cluster node to which we’ll be Live Migrating the VMs.
Lets use the Get-ClusterNode and Out-GridView cmdlets together to prompt for the
cluster node and store the value in a $targetClusterNode variable.
$targetClusterN ode =
Get-ClusterN ode -Cluster $clusterN ame |
Out-GridView -Title "Select Target Cluster N ode" `
-OutputMode Single

[8]

And then, we’ll need to create a list of all the VMs currently running in the cluster.
We can use the Get-ClusterGroup cmdlet to retrieve this list. Below, we have an
example where we are combining this cmdlet with a Where-Object cmdlet to return
only the virtual machine cluster groups that are running on any node except the
selected target cluster node. After all, it really doesn’t make any sense to Live Migrate a
VM to the same node on which it’s currently running!
$haVMs =
Get-ClusterGroup -Cluster $clusterN ame |
Where-Object {($_.GroupType -eq "VirtualMachine") `
-and ($_.OwnerN ode -ne $targetClusterN ode.N ame)}
We’ve stored the resulting list of VMs in a $haVMs variable.

Ready to Live Migrate!
OK … Now we have all of our variables defined for the cluster, the target cluster node
and the list of VMs from which to choose. Here’s our single line of PowerShell to do
the magic …
$haVMs |
Out-GridView -Title "Select VMs to Move" –PassThru |
Move-ClusterVirtualMachineRole -MigrationType Live `
-N ode $targetClusterN ode.N ame -Wait 0

[9]

Proceed with care: Keep in mind that your target cluster node will need to have
sufficient available resources to run the VM's that you select for Live Migration. Of
course, it's best to initially test tasks like this in your lab environment first.
Here’s what is happening in this single PowerShell command line:
We’re passing the list of VMs stored in the $haVMs variable to the Out-GridView
cmdlet.
Out-GridView prompts for which VMs to Live Migrate and then passes the selected
VMs down the PowerShell object pipeline to the MoveClusterVirtualMachineRole cmdlet.
This cmdlet initiates the Live Migration for each selected VM, and because it’s using
a
–Wait 0 parameter, it initiates each Live Migration one-after-another without
waiting for the prior task to finish.
As a result, all of the selected VMs will Live Migrate in parallel, up to the maximum
number of concurrent Live Migrations that you’ve configured on these cluster nodes.
The VMs selected beyond this maximum will simply queue up and wait their turn.
Unlike some competing hypervisors, Hyper-V doesn't impose an artificial hard-coded
limit on the number of VMs that can be Live Migrated concurrently. Instead, it's up to
you to set the maximum to a sensible value based on your hardware and network
capacity.

Do you have your own PowerShell automation ideas for Hyper-V?
Feel free to share your ideas in the Comments section below.
See you in the Clouds!
- Keith
1. http://blogs.technet.com/KeithMayer/ProfileUrlRedirect.ashx
2. http://blogs.technet.com/b/keithmayer/archive/2012/10/04/31days_2d00_winserv_2d00_livemigration.aspx
3. http://aka.ms/dlws2012rtm
4. http://aka.ms/hv2012gs
5. http://blogs.technet.com/cfs-file.ashx/__key/communityserver-blogs-componentsweblogfiles/00-00-00-94-09-metablogapi/image_5F00_444C2053.png
6. http://blogs.technet.com/cfs-file.ashx/__key/communityserver-blogs-componentsweblogfiles/00-00-00-94-09-metablogapi/image_5F00_444C2053.png
7. http://technet.microsoft.com/en-us/library/ee461009.aspx
8. http://blogs.technet.com/cfs-file.ashx/__key/communityserver-blogs-componentsweblogfiles/00-00-00-94-09-metablogapi/image_5F00_0418978A.png
9. http://blogs.technet.com/cfs-file.ashx/__key/communityserver-blogs-componentsweblogfiles/00-00-00-94-09-metablogapi/image_5F00_0ED87F90.png

More Related Content

More from Vision Concepts Infrastructure Services Solution

More from Vision Concepts Infrastructure Services Solution (20)

Palo Alto Networks VM-Series firewall now available on NetScaler SDX Platform
Palo Alto Networks VM-Series firewall now available on NetScaler SDX PlatformPalo Alto Networks VM-Series firewall now available on NetScaler SDX Platform
Palo Alto Networks VM-Series firewall now available on NetScaler SDX Platform
 
Citrix Application Lifecycle Management
Citrix Application Lifecycle ManagementCitrix Application Lifecycle Management
Citrix Application Lifecycle Management
 
Using Windows Azure as a SharePoint Disaster Recovery Environment
Using Windows Azure as a SharePoint Disaster Recovery EnvironmentUsing Windows Azure as a SharePoint Disaster Recovery Environment
Using Windows Azure as a SharePoint Disaster Recovery Environment
 
Delivery-on-Demand Company Raises $16 Million, Questions About Safety and Out...
Delivery-on-Demand Company Raises $16 Million, Questions About Safety and Out...Delivery-on-Demand Company Raises $16 Million, Questions About Safety and Out...
Delivery-on-Demand Company Raises $16 Million, Questions About Safety and Out...
 
Security Testing Using Infrastructure-As-Code
Security Testing Using Infrastructure-As-CodeSecurity Testing Using Infrastructure-As-Code
Security Testing Using Infrastructure-As-Code
 
Could Google end sweatshop labor?
Could Google end sweatshop labor?Could Google end sweatshop labor?
Could Google end sweatshop labor?
 
How to Change the IT Architect Hiring Practice
How to Change the IT Architect Hiring PracticeHow to Change the IT Architect Hiring Practice
How to Change the IT Architect Hiring Practice
 
NetApp To Offer Integrated Storage Array And Virtualization Software
NetApp To Offer Integrated Storage Array And Virtualization SoftwareNetApp To Offer Integrated Storage Array And Virtualization Software
NetApp To Offer Integrated Storage Array And Virtualization Software
 
Big Data - Security Concerns
Big Data - Security ConcernsBig Data - Security Concerns
Big Data - Security Concerns
 
Apple adding hundreds of new engineers and operations staff in China to speed...
Apple adding hundreds of new engineers and operations staff in China to speed...Apple adding hundreds of new engineers and operations staff in China to speed...
Apple adding hundreds of new engineers and operations staff in China to speed...
 
Data Analytics and the Ubiquitous Internet of Things
Data Analytics and the Ubiquitous Internet of ThingsData Analytics and the Ubiquitous Internet of Things
Data Analytics and the Ubiquitous Internet of Things
 
Citrix UniPrint NetGain Case Study
Citrix UniPrint NetGain Case StudyCitrix UniPrint NetGain Case Study
Citrix UniPrint NetGain Case Study
 
Uniprint Infinity Citrix Printing Solution
Uniprint Infinity Citrix Printing SolutionUniprint Infinity Citrix Printing Solution
Uniprint Infinity Citrix Printing Solution
 
The CIO Pocket MBA
The CIO Pocket MBAThe CIO Pocket MBA
The CIO Pocket MBA
 
Citrix Top 10 Trends
Citrix Top 10 Trends Citrix Top 10 Trends
Citrix Top 10 Trends
 
Citrix and Samsung Deliver Android Enterprise Security on Latest Samsung Gala...
Citrix and Samsung Deliver Android Enterprise Security on Latest Samsung Gala...Citrix and Samsung Deliver Android Enterprise Security on Latest Samsung Gala...
Citrix and Samsung Deliver Android Enterprise Security on Latest Samsung Gala...
 
Learn KVM and Receive Exclusive Invitation to Linux Foundation Collaboration ...
Learn KVM and Receive Exclusive Invitation to Linux Foundation Collaboration ...Learn KVM and Receive Exclusive Invitation to Linux Foundation Collaboration ...
Learn KVM and Receive Exclusive Invitation to Linux Foundation Collaboration ...
 
Using Concurrent Multipath Transmission for Transport Virtualization
Using Concurrent Multipath Transmission for Transport VirtualizationUsing Concurrent Multipath Transmission for Transport Virtualization
Using Concurrent Multipath Transmission for Transport Virtualization
 
GuideIT - Virtual Economies of Scale
GuideIT - Virtual Economies of Scale GuideIT - Virtual Economies of Scale
GuideIT - Virtual Economies of Scale
 
Build Your 2008R2 2-Node Cluster
Build Your 2008R2 2-Node ClusterBuild Your 2008R2 2-Node Cluster
Build Your 2008R2 2-Node Cluster
 

Recently uploaded

IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
Enterprise Knowledge
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
giselly40
 

Recently uploaded (20)

Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 

Live Migrate Multiple (Clustered) VMs in One Line of PowerShell - Revisited

  • 1. Step-by-Step: Live Migrate Multiple (Clustered) VMs in One Line of PowerShell Revisited KeithMayer[1] 24 Feb 2014 9:03 PM A while back, I wrote an article showing how to Live Migrate Your VMs in One Line of Powershell[2] between non-clustered Windows Server 2012 Hyper-V hosts using Shared Nothing Live Migration. Since then, I’ve been asked a few times for how this type of parallel Live Migration would be performed for highly available virtual machines between Hyper-V hosts within a cluster. In this article, we’ll walk through the steps of doing exactly that … via Windows PowerShell on Windows Server 2012 or 2012 R2[3] or our FREE Hyper-V Server 2012 R2[4] bare-metal, enterprise-grade hypervisor in a clustered configuration. Wait! Do I need PowerShell to Live Migrate multiple VMs within a Cluster? Well, actually … No. You could certainly use the Failover Cluster Manager GUI tool to select multiple highly available virtual machines, right-click and select Move | Live Migration … [5]
  • 2. [6] Failover Cluster Manager – Performing Multi-VM Live Migration But, you may wish to script this process for other reasons … perhaps to efficiently drain all VM’s from a host as part of a maintenance script that will be performing other tasks. Can I use the same PowerShell cmdlets for Live Migrating within a Cluster? Well, actually … No again. When VMs are made highly available resources within a cluster, they’re managed as cluster group resources instead of being standalone VM resources. As a result, we have a different set of Cluster-aware PowerShell cmdlets[7] that we use when managing these cluster groups. To perform a scripted multi-VM Live Migration, we’ll be leveraging three of these cmdlets: Now, let’s see that one line of PowerShell! Before getting to the point of actually performing the multi-VM Live Migration in a single PowerShell command line, we first need to setup a few variables to handle the "what" and "where" of moving these VMs. First, let’s specify the name of the cluster with which we’ll be working. We’ll store it in a $clusterName variable.
  • 3. $clusterName = read-host -Prompt "Cluster name" Next, we’ll need to select the cluster node to which we’ll be Live Migrating the VMs. Lets use the Get-ClusterNode and Out-GridView cmdlets together to prompt for the cluster node and store the value in a $targetClusterNode variable. $targetClusterN ode = Get-ClusterN ode -Cluster $clusterN ame | Out-GridView -Title "Select Target Cluster N ode" ` -OutputMode Single [8] And then, we’ll need to create a list of all the VMs currently running in the cluster. We can use the Get-ClusterGroup cmdlet to retrieve this list. Below, we have an example where we are combining this cmdlet with a Where-Object cmdlet to return only the virtual machine cluster groups that are running on any node except the selected target cluster node. After all, it really doesn’t make any sense to Live Migrate a VM to the same node on which it’s currently running! $haVMs = Get-ClusterGroup -Cluster $clusterN ame | Where-Object {($_.GroupType -eq "VirtualMachine") ` -and ($_.OwnerN ode -ne $targetClusterN ode.N ame)} We’ve stored the resulting list of VMs in a $haVMs variable. Ready to Live Migrate!
  • 4. OK … Now we have all of our variables defined for the cluster, the target cluster node and the list of VMs from which to choose. Here’s our single line of PowerShell to do the magic … $haVMs | Out-GridView -Title "Select VMs to Move" –PassThru | Move-ClusterVirtualMachineRole -MigrationType Live ` -N ode $targetClusterN ode.N ame -Wait 0 [9] Proceed with care: Keep in mind that your target cluster node will need to have sufficient available resources to run the VM's that you select for Live Migration. Of course, it's best to initially test tasks like this in your lab environment first. Here’s what is happening in this single PowerShell command line: We’re passing the list of VMs stored in the $haVMs variable to the Out-GridView cmdlet. Out-GridView prompts for which VMs to Live Migrate and then passes the selected VMs down the PowerShell object pipeline to the MoveClusterVirtualMachineRole cmdlet. This cmdlet initiates the Live Migration for each selected VM, and because it’s using a –Wait 0 parameter, it initiates each Live Migration one-after-another without waiting for the prior task to finish. As a result, all of the selected VMs will Live Migrate in parallel, up to the maximum number of concurrent Live Migrations that you’ve configured on these cluster nodes. The VMs selected beyond this maximum will simply queue up and wait their turn. Unlike some competing hypervisors, Hyper-V doesn't impose an artificial hard-coded limit on the number of VMs that can be Live Migrated concurrently. Instead, it's up to
  • 5. you to set the maximum to a sensible value based on your hardware and network capacity. Do you have your own PowerShell automation ideas for Hyper-V? Feel free to share your ideas in the Comments section below. See you in the Clouds! - Keith 1. http://blogs.technet.com/KeithMayer/ProfileUrlRedirect.ashx 2. http://blogs.technet.com/b/keithmayer/archive/2012/10/04/31days_2d00_winserv_2d00_livemigration.aspx 3. http://aka.ms/dlws2012rtm 4. http://aka.ms/hv2012gs 5. http://blogs.technet.com/cfs-file.ashx/__key/communityserver-blogs-componentsweblogfiles/00-00-00-94-09-metablogapi/image_5F00_444C2053.png 6. http://blogs.technet.com/cfs-file.ashx/__key/communityserver-blogs-componentsweblogfiles/00-00-00-94-09-metablogapi/image_5F00_444C2053.png 7. http://technet.microsoft.com/en-us/library/ee461009.aspx 8. http://blogs.technet.com/cfs-file.ashx/__key/communityserver-blogs-componentsweblogfiles/00-00-00-94-09-metablogapi/image_5F00_0418978A.png 9. http://blogs.technet.com/cfs-file.ashx/__key/communityserver-blogs-componentsweblogfiles/00-00-00-94-09-metablogapi/image_5F00_0ED87F90.png