Where I work, we were a little behind finally getting to Windows Server 2008 R2. Our Exchange Servers were running on Server 2003 R2 until recently. Windows clustering is quite different on 2k8 vs. 2k3. I wrote this function to move the Windows cluster group “Cluster Group” (quorum) to the other node of the cluster. I know it’s not that difficult to do this, but it saves a few extra keystrokes.
Function Invoke-WindowsClusterFailover
{
#Requires -version 2
[CmdletBinding(SupportsShouldProcess=$true,ConfirmImpact="High")]
param()
Write-Verbose "Checking to see if $($env:computername) is a Clustered Exchange Server"
Get-ClusteredMailboxServerStatus -ErrorAction SilentlyContinue | Out-Null
If ($? -eq $False)
{
Write-Verbose "$($env:computername) is not a clustered Exchange Server - Exiting"
Throw "$($env:computername) is not a clustered Exchange Server"
}
Else
{
Write-Verbose "$($env:computername) is a Clustered Exchange Server"
If (((Get-WmiObject Win32_OperatingSystem).Caption).ToString() -like "*2008*")
{
Write-Verbose "$($env:computername) is a Windows Server 2008 or later"
Write-Verbose "Loading Windows Failover Cluster PowerShell Module"
Import-Module FailoverClusters
}
Else
{
Write-Verbose "$($env:computername) is not Windows Server 2008 or later"
Write-Verbose "$((Get-WmiObject Win32_OperatingSystem).Caption) does not support the Powershell FailoverCluster Module - Exiting"
Throw "$((Get-WmiObject Win32_OperatingSystem).Caption) does not support the Powershell FailoverCluster Module"
}
Write-Verbose "Getting Windows Cluster Name"
$ClusterName = (Get-Cluster).Name
Write-Verbose "Checking ShouldContinue if OK to proceed"
if($PSCmdlet.ShouldProcess("$($ClusterName)", "Failover Windows Cluster"))
{
Write-Verbose "Moving Windows Cluster Group"
Get-ClusterGroup "Cluster Group" | Move-ClusterGroup
}
Write-Verbose "End"
}
.SYNOPSIS
Moves the Windows cluster "Cluster Group" to the other node of the cluster
.DESCRIPTION
Moves the Windows cluster "Cluster Group" to the other node of the cluster. This requires
Windows Server 2008 or later. This function supports "Should Continue" so it prompts the
user to continue at the "dangerous" portion of the function (Move-ClusterGroup). If you
don't want the should continue prompt, you can use the param.
.NOTES
Function Name: Invoke-WindowsClusterFailover
Author: Dan Burgess
Email: nerd@everydaynerd.com
Script Requires: Powershell 2.0 or higher; Windows Server 2008 or later
#>
}
I really enjoyed using the “SupportsShouldProcess” feature of CmdletBinding! Expand the code above, and double click to select all.
Related posts:
Microsoft DPM
MicrosoftExchange
Nerd with a .45