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 = ('').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!

1 Comment

  1. Kieran Williams July 2, 2021 at 3:15 pm

    Great work, do you know if there is a way to manually specify a different Port number? we don’t use the common 8443 for our controller.

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.