Previously we have face many issue with client on able to get IP because of DHCP scope gets full. We can take help of new DHCP module to monitor all scope on DHCP server and provides us mail.
Below Script will monitor all scopes in DHCP server using Get-DhcpServerv4ScopeStatistics and will mail to your email address. You can set your threshold on variable $threshold, which I have set it to 90.
Script can be scheduled for every 15 minutes or 30 minutes according to your preferences and critical scope.
Import-Module DHCP
$threshold = 90
$email_to = "admin_group@shanky.com”
$email_from = “Monitoring@shanky.com”
$email_server = “10.1.36.9”
$scopes = Get-DhcpServerv4ScopeStatistics
foreach ($scope in $scopes) {
if($scope.PercentageInUse -gt $threshold){
$email_body = “Scope: $($scope.ScopeId) – pool IPs in use is $([math]::round($scope.PercentageInUse, 0))% on $(hostname)”
Send-MailMessage -To $email_to -From $email_from -SmtpServer $email_server -Subject “Scope threshold exceeded – $($scope.ScopeId)” -Body $email_body
}
}
No comments:
Post a Comment