# The purpose of this script is to query every cluster you add to $AllClusters and pull
# back the cluster nodes, cluster groups, where each group resides and the status of # the group.
# Written by Brady Randolph of RBA Consulting
#Create $body array to add cluster info to
[string]$body = @()
#Creates credentials for each WMI query
$creds = Get-Credential -Credential "domain\user"
#Builds an array of cluster names
$AllClusters = "Cluster1","Cluster2"
Foreach ($cluster in $AllClusters){
$body += "`nCluster Name:`t$cluster`n"
$ClusterNodes = gwmi -Query "select * from MSCluster_ClusterToNode" -namespace root\mscluster -computername $cluster -credential $creds -impersonation 3 -authentication 6
foreach ($obj in $ClusterNodes){$obj = $obj.Dependent; $obj = $obj.TrimStart("MSCluster_Node.Name=");$obj = $obj.Trim(‘"’)
#adds string to $body array
$body += "Cluster Node:`t$obj`n"
}
$RG = gwmi -Query "select * from MSCluster_ResourceGroup" -namespace root\mscluster -computername $cluster -credential $creds -impersonation 3 -authentication 6
foreach ($groups in $RG) {$activenode = $groups.__SERVER; $GroupName = $groups.Name; $state = $groups.State
If ($state -eq 0){$state = "Online"}
elseif ($state -ne 0) {$state = "Error"}
$body += "Cluster Group:`t$GroupName`nGroup Owner:`t$activenode`nStatus:`t`t$state`n"
}
}
$to = "someone@domain.com"
$from = "you@domain.com"
$subject = "Microsoft Clusters Verification"
$smtpServer = "Your SMTP FQDN"
Send-MailMessage -To $to -From $from -Subject $subject -Body $body -SmtpServer $smtpServer
