Thursday, 29 October 2015

Generating Lync/Skype Option 120 Values for DHCP Servers

If your Lync or Skype for Business deployment includes Lync Phone Edition devices, you are probably familiar with the DHCP configuration work necessary to get phones to find the Lync or Skype pool for registration and log in.

The standard way is to use DHCPUtil.exe to give you all the values you need for your DHCP server settings. This works, but can be tedious if you have a lot of servers to configure - a PowerShell script would be better.

I recently needed to reconfigure our DHCP servers for a number of Lync server changes, and wanted a quick way to generate Option 120 values. After a little bit of research I found out how the Option 120 value is constructed. There is a nice write-up on 'Chris and Robin's Technology Blog', here.

So now that I know what the finished value looks like, I could write the PowerShell script. It turned out to be pretty simple. The only extra step I added was to include the option to split the string up into characters separated by a colon, as that is the format our non-Microsoft DHCP server requires.

The script takes two parameters -the SIP server and the optional delimeter.

# Get-DhcpOption120.ps1
# Script to retrieve greetings from an Exchange UM Mailbox
# Ben Lye -

# Parameters for the script
 [Parameter(Mandatory=$true)] $SipServer,
 [Parameter(Mandatory=$False)] $Delimeter = ""

# Initialise an empty string to store the output
$HexString = $Null

# Split the sip server FQDN up into component parts and loop over each part
ForEach ($Part in @($SipServer.Split("."))) {
 # Put the length of this part into the output string
 $HexString = $HexString + "{0:X2}" -f $Part.Length
 # Convert each character in the part to hex and append to the string
 Foreach ($Char in $Part.ToCharArray()) {
  $HexString = $HexString + [System.String]::Format("{0:X2}", [System.Convert]::ToUInt32($Char))

# Prepend and append '00' to the beginning and end of the string
$HexString = "00" + $HexString + "00"

# Split the string up by the delimiter
$HexString = $HexString -replace '(..(?!$))' , "`$1$Delimeter"

# Return the converted string
Return $HexString
Download Script

Now that I have the script I can use it to quickly generate Option 120 values for all my SIP domains:
Get-CsSipDomain | % {$Fqdn = "sip.$($_.Name)"; $Option120 = .\Get-DhcpOption120.ps1 -SipServer $Fqdn -Delimeter ":"; "$Fqdn `t $Option120"}

- Ben

No comments:

Post a Comment