NLB -Notify When Node Drained

A little code snipped to email you when the NLB node you are Drain Stopping is drained.

I find it handy as it can take a while to drainstop a server. This will check the state of the server and email you when it is stopped. Meaning you can get on with real work. Requires a SNMP server and the NLB RSAT Powershell tools installed

 

$Computername = "yourserver"
$NodeStatus = get-nlbclusternode -nodename $Computername -hostname $Computername
do
{
$NodeStatus   
sleep 60
$NodeStatus = get-nlbclusternode -nodename $Computername -hostname $Computername
}
until ($NodeStatus.state.NodeStatusCode -eq "Stopped")


$MessageBody = "NLBDrained"
Write-host $MessageBody -foreground red
$smtpServer = "smtp.domain.com"
$msg = new-object Net.Mail.MailMessage
$smtp = new-object Net.Mail.SmtpClient($smtpServer)
$MailFrom = "YourAddress@yourdomain.com"
$msg.From = $MailFrom
$Mailto = "YourAddress@yourdomain.com"

ForEach ($element in $Mailto) {
  $msg.To.Add($element)
}
$msg.Subject = "NLB Node $Computername Drained"
$msg.IsBodyHTML = $true
$msg.body = "$MessageBody"
$smtp.Send($msg)

 

Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.