Friday, February 22, 2013

Hyper-V: Managing Failover IP Configuration with PowerShell

So it seems that managing failover TCP/IP configuration in Hyper-V replica is a bit of a pain.  There is no VMM integration (why?) and to manage anything but a small lab style deployment you are going to need some PowerShell.

Here is a basic script that will set the failover TCP/IP configuration on a set of VMs on a cluster, then talk to another cluster and set the same configuration on the replica machine.

 Get-ClusterGroup -Cluster CLUSTER1 | `
# Get all cluster groups that are VMs and are not 'Locked'
# A Locked cluster group means that it is a replica machine itself
where-object {$_.GroupType -eq 'VirtualMachine' -and $_.StatusInformation -ne 'Locked'} | `
foreach {
if ((get-vm -name $_.Name -ComputerName $_.OwnerNode).ReplicationState -ne 'Disabled') {

$ip = (Get-VMNetworkAdapter -ComputerName $_.OwnerNode -vmname $_.Name).IpAddresses[0];

Set-VMNetworkAdapterFailoverConfiguration -VMNetworkAdapter (Get-VMNetworkAdapter -ComputerName $_.OwnerNode -vmname $_.Name) `
-IPv4Address $ip `
-IPv4SubnetMask 255.255.255.0 `
-IPv4DefaultGateway 172.22.20.250 `
-IPv4PreferredDNSServer 172.22.20.1 `
-IPv4AlternateDNSServer 172.22.20.2

# now do other side

get-clustergroup -Cluster CLUSTER2 -Name $_.Name | `
foreach { Set-VMNetworkAdapterFailoverConfiguration -VMNetworkAdapter (Get-VMNetworkAdapter -ComputerName $_.OwnerNode -vmname $_.Name) `
-IPv4Address $ip `
-IPv4SubnetMask 255.255.255.0 `
-IPv4DefaultGateway 172.22.20.250 `
-IPv4PreferredDNSServer 172.22.20.1 `
-IPv4AlternateDNSServer 172.22.20.2
} #end other side
} #end if vm is replicating
} #end foreach VM found

 


I hope you find it useful Smile

No comments:

Post a Comment