Had an influx of folks come into the office last week and one of our DHCP Scopes actually almost ran out of available addresses (which I found out after the fact by chance). This inspired me to make a quick PowerShell script deployed as a scheduled task to notify me when a scope is low on available addresses, as seen below:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
#SMTP Variables $strSMTPServer = "smtp@domain.com" $strSMTPTo = "AnotherITGuy <email@domain.com>" $strSMTPFrom = "DHCP Alerts <alerts@domain.com>" $strSMTPSubject = "Available Addresses for XScope Low" $strSMTPBody = "XScope has less that 10 available addresses left" #Pull Scope Lease info into an array $arrXScopeDHCPLeases = Get-DhcpServerv4Lease -ScopeId "10.0.0.0" -AllLeases #Total assignable addresses in scope $intXScopeTotalAddresses = 95 #Number of available addresses left $intXScopeFreeAddresses = $intXScopeTotalAddresses - $arrXScopeDHCPLeases.Count ################ #Let's Do Stuff# ################ #Send email if less than or equal to 10 free addresses if($intXScopeFreeAddresses -le 10) { Send-MailMessage -SmtpServer $strSMTPServer -To $strSMTPTo -From $strSMTPFrom -Priority High -Subject $strSMTPSubject -Body $strSMTPBody } |