{"id":13821,"date":"2012-11-22T13:08:00","date_gmt":"2012-11-22T13:08:00","guid":{"rendered":"https:\/\/aidanfinn.com\/?p=13821"},"modified":"2012-11-22T13:08:00","modified_gmt":"2012-11-22T13:08:00","slug":"build-a-windows-server-2012-hyper-v-cluster-using-powershell","status":"publish","type":"post","link":"https:\/\/aidanfinn.com\/?p=13821","title":{"rendered":"Build a Windows Server 2012 Hyper-V Cluster Using PowerShell"},"content":{"rendered":"<p>I\u2019ve previously <a href=\"https:\/\/aidanfinn.com\/?p=12592\" target=\"_blank\">posted<\/a> a short and basic script that would build a Hyper-V Failover Cluster, but I\u2019ve updated that script since for use in demos.&#160; You can find my new script below.<\/p>\n<p>What does it do?<\/p>\n<ol>\n<li>A new cluster is built with no attached storage.&#160; My latest incarnation of my demos uses a Scale-Out File Server for the storage. <\/li>\n<li>It renames the cluster networks. Note that I\u2019ve used converged fabrics via a virtual switch. <\/li>\n<li>Runs a function called Add-VMsToCluster which will scan all the cluster nodes for VMs to make them highly available <\/li>\n<li>Add-VMsToCluster will run a workflow which will in turn add VMs to the cluster in parallel (up to 5 at a time \u2013 a POSH subsystem restriction that Jeff Wouters helped me identify) rather than one at a time (which would be slower) <\/li>\n<\/ol>\n<p>Things missing from the script:<\/p>\n<ul>\n<li>There\u2019s no error checking <\/li>\n<li>Damned if I can find out how to set the Live Migration network <em>for a cluster<\/em>.&#160; Don\u2019t bother sending me your POSH cmdlets for configuring Live Migration networks for non-clustered hosts; that has no effect on clustered hosts. <\/li>\n<\/ul>\n<p>Here\u2019s the script:<\/p>\n<p>####<\/p>\n<p># Written by Aidan Finn, @joe_elway, <a href=\"https:\/\/aidanfinn.com\">https:\/\/aidanfinn.com<\/a>    <br \/># Author of Windows Server 2012 Hyper-V Installation And Configuration Guide    <br \/>#    <br \/># Copyright    <br \/>###########    <br \/># You may use and modify this script free of charge and without permission.    <br \/># You may not reproduce or share this script. Please forward people to this    <br \/># this page instead.    <br \/>#    <br \/># Waiver    <br \/>########    <br \/># You are solely responsible for testing and using this script and any     <br \/># results\/problems. There is no support for this script.<\/p>\n<p>Workflow Invoke-AddVMToCluster    <br \/>{     <br \/>Param (     <br \/>[parameter(Mandatory=$true)][String[]] $VMList,     <br \/>[parameter(Mandatory=$true)][String[]] $ClusterName     <br \/>)<\/p>\n<p>[string]$TheCluster = $ClusterName<\/p>\n<p>ForEach -Parallel ($VM in $VMList)    <br \/>&#160;&#160;&#160; {     <br \/>&#160;&#160;&#160; Add-ClusterVirtualMachineRole -VMName $VM -Cluster $TheCluster     <br \/>&#160;&#160;&#160; }     <br \/># End of workflow     <br \/>}<\/p>\n<p>Function Add-VMsToCluster ($ClusterName)     <br \/>{     <br \/>$ClusterNodes = Get-ClusterNode -Cluster $ClusterName<\/p>\n<p>ForEach ($AddNode in $ClusterNodes)    <br \/>&#160;&#160;&#160; {     <br \/>&#160;&#160;&#160; $VMList = Get-VM -Name * -ComputerName $AddNode     <br \/>&#160;&#160;&#160; If ($VMList -ne $null)     <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; {     <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; Invoke-AddVMToCluster -VMList $VMList.Name $ClusterName     <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; }     <br \/>&#160;&#160;&#160; }     <br \/># End of function     <br \/>}<\/p>\n<p># The script starts here     <br \/>CLS     <br \/>Write-Host &quot;Creating the cluster&quot;     <br \/>New-Cluster -Name demo-hvc1 -StaticAddress 192.168.1.61 -Node demo-host1, demo-host2 -NoStorage<\/p>\n<p>Write-Host &quot;Waiting 10 seconds for the cluster to initialise&quot;    <br \/>Start-Sleep -s 10<\/p>\n<p># This cluster is using storage provided by a Scale-Out File Server instead of traditional SAN   <br \/>Write-Host &quot;Configuring quorum to use file share witness&quot;    <br \/>Set-ClusterQuorum -NodeAndFileShareMajority \\demo-sofs1HVC1-Witness<\/p>\n<p>Write-Host &quot;Renaming the cluster networks&quot;    <br \/>(Get-ClusterNetwork | where-object {$_.Address -eq &quot;172.16.1.0&quot;}).Name = &quot;vEthernet (Host-Cluster)&quot;     <br \/>(Get-ClusterNetwork | where-object {$_.Address -eq &quot;172.16.2.0&quot;}).Name = &quot;vEthernet (Host-LiveMigration)&quot;     <br \/>(Get-ClusterNetwork | where-object {$_.Address -eq &quot;192.168.1.0&quot;}).Name = &quot;vEthernet (Host-Parent)&quot;     <\/p>\n<p>Write-Host &quot;Adding any existing VMs to the cluster&quot;    <br \/>Add-VMsToCluster &quot;demo-hvc1&quot;<\/p>\n<p>####<\/p>\n<p>This information has been brought to you by <a href=\"http:\/\/www.amazon.com\/Windows-Server-Hyper-V-Installation-Configuration\/dp\/1118486498%3FSubscriptionId%3DAKIAIJ5WNI7ZSH7W4OXA%26tag%3Dafm0c-20%26linkCode%3Dxm2%26camp%3D2025%26creative%3D165953%26creativeASIN%3D1118486498\" target=\"_blank\">Windows Server 2012 Hyper-V Installation and Configuration Guide<\/a> (available on pre-order on Amazon) where you\u2019ll find lots of PowerShell like in this script:<\/p>\n<p><a href=\"http:\/\/www.amazon.com\/Windows-Server-Hyper-V-Installation-Configuration\/dp\/1118486498%3FSubscriptionId%3DAKIAIJ5WNI7ZSH7W4OXA%26tag%3Dafm0c-20%26linkCode%3Dxm2%26camp%3D2025%26creative%3D165953%26creativeASIN%3D1118486498\" target=\"_blank\"><img loading=\"lazy\" decoding=\"async\" title=\"image\" style=\"float: none; margin-left: auto; display: block; margin-right: auto\" border=\"0\" alt=\"image\" src=\"https:\/\/aidanfinn.com\/wp-content\/uploads\/2012\/09\/image_thumb19.png\" width=\"196\" height=\"244\" \/><\/a><\/p>\n<div id=\"scid:0767317B-992E-4b12-91E0-4F059A8CECA8:6a728a80-0139-4f0b-b98e-f787677a6112\" class=\"wlWriterEditableSmartContent\" style=\"float: none; padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px\">Technorati Tags: <a href=\"http:\/\/technorati.com\/tags\/Hyper-V\" rel=\"tag\">Hyper-V<\/a>,<a href=\"http:\/\/technorati.com\/tags\/Virtualisation\" rel=\"tag\">Virtualisation<\/a>,<a href=\"http:\/\/technorati.com\/tags\/Failover+Clustering\" rel=\"tag\">Failover Clustering<\/a>,<a href=\"http:\/\/technorati.com\/tags\/PowerShell\" rel=\"tag\">PowerShell<\/a><\/div>\n","protected":false},"excerpt":{"rendered":"<p>I\u2019ve previously posted a short and basic script that would build a Hyper-V Failover Cluster, but I\u2019ve updated that script since for use in demos.&#160; You can find my new script below. What does it do? A new cluster is built with no attached storage.&#160; My latest incarnation of my demos uses a Scale-Out File &hellip; <a href=\"https:\/\/aidanfinn.com\/?p=13821\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Build a Windows Server 2012 Hyper-V Cluster Using PowerShell&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"_uf_show_specific_survey":0,"_uf_disable_surveys":false,"footnotes":""},"categories":[20],"tags":[63,181,87,195],"class_list":["post-13821","post","type-post","status-publish","format-standard","hentry","category-hyper-v","tag-failover-clustering","tag-hyper-v","tag-powershell","tag-virtualisation"],"aioseo_notices":[],"jetpack_featured_media_url":"","amp_enabled":true,"_links":{"self":[{"href":"https:\/\/aidanfinn.com\/index.php?rest_route=\/wp\/v2\/posts\/13821","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/aidanfinn.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/aidanfinn.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/aidanfinn.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/aidanfinn.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=13821"}],"version-history":[{"count":0,"href":"https:\/\/aidanfinn.com\/index.php?rest_route=\/wp\/v2\/posts\/13821\/revisions"}],"wp:attachment":[{"href":"https:\/\/aidanfinn.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=13821"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/aidanfinn.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=13821"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/aidanfinn.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=13821"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}