Featured image of post Automating with PowerShell: Deploying Unifi DHCP Options

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!

All blogs are posted under AGPL3.0 unless stated otherwise
comments powered by Disqus
Built with Hugo
Theme Stack designed by Jimmy