Automating with PowerShell: Deploying Unifi DHCP Options

Hey all! a bit shorter one today as I am swamped at the office.

Last week one of my friends was working on deploying DHCP options to automatically adopt devices inside networks managed by a Windows DHCP server. The process is pretty straight forward – Add a vendor class, add the option, and set it to the correct IP address. Unfortunately, that of course means a lot of clicking in the DHCP console on each Windows Server he manages.

So, he asked me if I could simplify this for him by scripting it, so this short snippet can be used to set the DHCP options for all scopes, on a Windows Server to automatically adopt Unifi devices.

$ControllerIP = ('10.8.8.8').split('.') | ForEach-Object { '{0:x}' -f $_ }
Add-DhcpServerv4Class -Name "ubnt" -Type Vendor -Data "ubnt"
Add-DhcpServerv4OptionDefinition -Name "UniFiController" -OptionId 1 -Type "BinaryData" -VendorClass "ubnt" -Description "IP as Hex Object"
Get-DhcpServerv4Scope | Set-DhcpServerv4OptionValue -VendorClass 'ubnt' -OptionId 001 -Value $ControllerIP

all that you need to change is the IP of your controller, and that’s all folks! like I said; short but sweet.

As always, Happy PowerShelling!

Recent Articles

Automating with PowerShell: making stolen tokens useless with Global Secure Access

Last week I watched Merill Fernando talk to Alex Pavlovsky and Marilee Tuscak from the Entra team about something I’d kinda put under the “needs a GSA licence” branch and i’d check it out later, turns out that like most people, I half-assed the documentation and it turns out it doesn’t. There’s two features that come with any P1 license; Compliant network check and Source IP Restoration. So BP, P1, or even frontline worker licenses already have this.

CIPP ❤️ #IntuneForMSPs

We’re Joining #IntuneForMSPs 🎉

Being invited by Microsoft to join a global initiative is a big moment for us, and we want to be clear about why it matters. #IntuneForMSPs is Microsoft’s program to help MSPs deliver Microsoft 365, Intune, and Copilot services at scale, and CIPP is now part of it, bringing the largest MSP community in the channel directly to Microsoft.

The return of CyberDrain CTF

CyberDrain CTF returns! (and so do I!)

It’s been since september that I actually picked up a digital pen equivalent and wrote anything down. This was due to me being busy with life but also my side projects like CIPP. I’m trying to get back into the game of scripting and blogging about these scripts. There’s still so much to automate and so little time, right? ;)