Powershell Needful Things put that in your pipeline


Windows 2008 R2 DHCP Scope Utilisation Report

Just a quick little script I developed for a client this week. As you know Windows 2012 DHCP server has some pretty cool Powershell cmdlets built in, but sadly, in the case of Windows 2008 there are none.

My customer needed to know when scopes are starting to run out of addresses. I found that the DHCP server logs an event each hour after startup for all scopes that are at 80% utilisation or more.

My solution was the following script. The script is triggered by the 1020 event in the system log, and then finds the events for the last hour, and send an email to the guys to alert them.

You need to modify the script for your servers SMTP parameters and if you prefer to run the script remotely you can use -computername on the the get-eventlog cmdlet.

Admittedly, this is not the best way if you have something like SCOM in place, but as a rudimentary solution it does exactly what they need.

$eventList = @()
Get-EventLog -LogName System -After (get-date).AddHours(-1) -Source DhcpServer -InstanceId 1020 `
| foreach-Object {
$row = "" | Select ScopeAddress, Utilization, FreeIPAddresses
$row.ScopeAddress = $_.ReplacementStrings[0]
$row.Utilization= $_.ReplacementStrings[1]
$row.FreeIPAddresses = $_.ReplacementStrings[2]
$eventList += $row

$messageParameters = @{
Subject = "DHCP Scope Utilisation Report - $((Get-Date))"
Body = $eventList | Sort Utilization -Descending |
ConvertTo-Html |
From = "Scope Alert <scopealert@xyz.com>"
To = "group@xyz.com"
SmtpServer = "xxx.xxx.xxx.xxx"

Send-MailMessage @messageParameters -BodyAsHtml
Comments (3) Trackbacks (0)
  1. Hi!

    Wonderful scipt! Have it automating cleanup of my user home share.

    Can you modify it so its usable on profileshares too?
    Dont know what to mod in order for it to leave out the .V2 ending if its present.

    regards Marius

    • Missplaced. Was for orphaned folder script. FindOrphan.ps1. 🙂

      • Hi Marius,

        Thanks for using the script, and thanks for the feedback!

        I would imagine that you could adapt the script to cleanup profile folders, as the logic for the cleaning is there. It would involve some work though.


Leave a comment

No trackbacks yet.