Power-Shell Scripts to build Win2012 Hyper V Cluster
How will it happen ?
- A new cluster is built with no attached SAN.
- It will perform naming on the cluster networks. Note that I’ve used converged fabrics via a virtual switch.
- Execution via called Add-VMsToCluster which will then scan all the cluster nodes for existing VMs to make them HA mode.
- Add-VMsToCluster will run a workflow which will in turn add VMs to the cluster in parallel.
##########################################
# Written by GuoWen Su, geeky-gw.
#
#
# Copyright
##########################################
# You may use and modify this script free of charge and without permission.
# You may not reproduce or share this script. Please forward people to this
# this page instead.
#
Workflow Invoke-AddVMToCluster
{
Param (
[parameter(Mandatory=$true)][String[]] $VMList,
[parameter(Mandatory=$true)][String[]] $ClusterName
)
[string]$TheCluster = $ClusterName
ForEach -Parallel ($VM in $VMList)
{
Add-ClusterVirtualMachineRole -VMName $VM -Cluster $TheCluster
}
# End of workflow
}
Function Add-VMsToCluster ($ClusterName)
{
$ClusterNodes = Get-ClusterNode -Cluster $ClusterName
ForEach ($AddNode in $ClusterNodes)
{
$VMList = Get-VM -Name * -ComputerName $AddNode
If ($VMList -ne $null)
{
Invoke-AddVMToCluster -VMList $VMList.Name $ClusterName
}
}
# End of function
}
# The script starts here
CLS
Write-Host "Creating the cluster"
New-Cluster -Name demo-hvc1 -StaticAddress 192.168.1.61 -Node demo-host1, demo-host2 -NoStorage
Write-Host "Waiting 10 seconds for the cluster to initialise"
Start-Sleep -s 10
# This cluster is using storage provided by a Scale-Out File Server instead of traditional SAN
Write-Host "Configuring quorum to use file share witness"
Set-ClusterQuorum -NodeAndFileShareMajority \\demo-sofs1\HVC1-Witness
Write-Host "Renaming the cluster networks"
(Get-ClusterNetwork | where-object {$_.Address -eq "172.16.1.0"}).Name = "vEthernet (Host-Cluster)"
(Get-ClusterNetwork | where-object {$_.Address -eq "172.16.2.0"}).Name = "vEthernet (Host-LiveMigration)"
(Get-ClusterNetwork | where-object {$_.Address -eq "192.168.1.0"}).Name = "vEthernet (Host-Parent)"
Write-Host "Adding any existing VMs to the cluster"
Add-VMsToCluster "demo-hvc1"
####
No comments:
Post a Comment