Skip to content

Instantly share code, notes, and snippets.

@norman-bauer
Last active December 31, 2022 08:24
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save norman-bauer/52e28559d8d4420169784bce70873122 to your computer and use it in GitHub Desktop.
Save norman-bauer/52e28559d8d4420169784bce70873122 to your computer and use it in GitHub Desktop.
Asks for a list of semicolon separated domain suffixes and a Windows Server DHCP Scope Id on which Option 119 will be configured accordingly
$domainSearchList = Read-Host "Please enter a list of domain suffixes separated by semicolons (e.g. domain.local;domain.tld;int.domain.tld)"
$scopeToConfigure = Read-Host "Please enter the scope id of the scope to be configured (e.g. 192.168.1.0)"
$splittedDomainSearchList = $domainSearchList -split "\;"
$domainSearchListHexArray = @();
Foreach ($domain in $splittedDomainSearchList)
{
$splittedDomainParts = $domain -split "\."
Foreach ($domainPart in $splittedDomainParts)
{
$domainPartHexArray = @()
$domainPartHexArray += $domainPart.Length
$domainPartHexArray += $domainPart.ToCharArray();
Foreach ($item in $domainPartHexArray)
{
$domainSearchListHexArray += [System.Convert]::ToUInt32($item)
}
}
$domainSearchListHexArray+= 0x00
}
Set-DhcpServerv4OptionValue -ScopeId $scopeToConfigure -OptionId 119 -Value $domainSearchListHexArray
@hevisko
Copy link

hevisko commented Apr 21, 2021

If you (like me) need to use this function to calculate for a device like a FortiGate, then the string you need is produced with:

-join ($domainSearchListHexArray | % {“{0:X2}” -f $_})

(ie. don't do the Set-DhcpServer.... part)

@hevisko
Copy link

hevisko commented Apr 21, 2021

Note2: This function doesn't do compaction as per the RFCs where you have multiple search domains sharing a suffix, like: test.com;lab.test.com;prod.test.com where the encoding refers back to the first use of the suffix (in this case test.com) to shorten the DHCP option string

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment