DHCP-Option 12 missing after DHCP-Server restart

ErazerMe 46 Reputation points
2021-06-22T15:28:30.563+00:00

We are using DHCP-Reservation to provide an IP-adress to our clients. Additional we use the DHCP-Option 12 to handle the Hostname of the client.

The DHCP-reservation (including the option12) were set within a powershell script to decrease the manual tasks.
We noticed, that the DHCP-Option 12 of IP-Reservation (which was set with the command "Set-DhcpServerv4OptionValue") will be resetted after a restart of the DHCP-Server.
Note: when you do this step manually within the GUI, the problem does not occure.

Summarized: setting the option 12 to a DHCP-Reservation with command "Set-DhcpServerv4OptionValue", will be resetted after restarting the DHCP-Services.
Can anyone provide me a workaround or does anyone have a idea how I can solve the issue?

Attached you can find a short Powershell-Snippet which you can use to reproduce the problem:

Blockquote

Ensure that you have a IP-Scope with 192.168.10.0

$ipscope = "192.168.10.0"
$ipscope_start = "192.168.10.1"
$ipscope_end = "192.168.10.254"
$ipscope_subnetmask = "255.255.255.0"
[ipaddress]$ip = "192.168.10.18" #Mention your IP-Adress you want to test
$DHCPServer = "TEMPLATE_W2K16" #Mention the Servername of your testserver

Add-DhcpServerv4Scope -ComputerName $DHCPServer -StartRange $ipscope_start -EndRange $ipscope_end -Name $ipscope -SubnetMask $ipscope_subnetmask
Add-DhcpServerv4Reservation -ComputerName $DHCPServer -ScopeId $ipscope -IPAddress $ip -ClientId "11-22-33-44-55-66" -Name "Initialname"

For($i=0; $i -le 5;$i++)
{
$reservationname = "Name$i"
Set-DhcpServerv4Reservation -IpAddress $ip -ClientId 11-22-33-44-55-66 -Name $reservationname -Description $reservationname -Type Dhcp -ComputerName $DHCPServer
Set-DhcpServerv4OptionValue -ReservedIP $ip -OptionId 12 -Value $reservationname -ComputerName $DHCPServer
$OptionValue1 = Get-DhcpServerv4OptionValue -ReservedIP $Ip -ComputerName $DHCPServer
Write-host "Current Option: $($OptionValue1.Value)"
Read-host "Restart DHCP-Service?"
Restart-Service DHCPServer
sleep -Seconds 5
$OptionValue2 = Get-DhcpServerv4OptionValue -ReservedIP $Ip -ComputerName $DHCPServer
Write-Host "Option12 we want to set: $reservationname"
Write-host "Option12 after restart: $($OptionValue2.Value)"
Read-host "Next try?"
}

Windows Server 2016
Windows Server 2016
A Microsoft server operating system that supports enterprise-level management updated to data storage.
2,377 questions
Windows Server
Windows Server
A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.
12,170 questions
Windows DHCP
Windows DHCP
Windows: A family of Microsoft operating systems that run across personal computers, tablets, laptops, phones, internet of things devices, self-contained mixed reality headsets, large collaboration screens, and other devices.DHCP: Dynamic Host Configuration Protocol (DHCP). A communications protocol that lets network administrators manage centrally and automate the assignment of Internet Protocol (IP) addresses in an organization's network.
1,023 questions
Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,381 questions
0 comments No comments
{count} votes

Accepted answer
  1. Rich Matheisen 45,091 Reputation points
    2021-06-23T21:52:42.967+00:00

    Well, that is just bonkers! The value changes in the MMC but it's lost after restarting the service. Looks like a bug to me!

    You can try this as a work-around. The Remove-DhcpServerv4OptionValue will fail in the 1st iteration because I didn't bother to set it outside the loop, but it's just a demo so don't let it bother you:

    #Ensure that you have a IP-Scope with 192.168.10.0
    $ipscope = "192.168.10.0"
    $ipscope_start = "192.168.10.1"
    $ipscope_end = "192.168.10.254"
    $ipscope_subnetmask = "255.255.255.0"
    [ipaddress]$ip = "192.168.10.18" #Mention your IP-Adress you want to test
    $DHCPServer = "SRV02" #Mention the Servername of your testserver
    
    Add-DhcpServerv4Scope -ComputerName $DHCPServer -StartRange $ipscope_start -EndRange $ipscope_end -Name $ipscope -SubnetMask $ipscope_subnetmask
    Add-DhcpServerv4Reservation -ComputerName $DHCPServer -ScopeId $ipscope -IPAddress $ip -ClientId "11-22-33-44-55-66" -Name "Initialname"
    
    For ($i = 0; $i -le 5; $i++) {
        Remove-DhcpServerv4OptionValue -ComputerName $DHCPServer -OptionID 12 -ReservedIP $ip
        Remove-DhcpServerv4Reservation -ComputerName $DHCPServer -ReservedIP $IP
    
        $reservationname = "Name$i"
    
        Add-DhcpServerv4Reservation -ComputerName $DHCPServer -ScopeId $ipscope -IPAddress $ip -ClientId "11-22-33-44-55-66" -Name $reservationname -Description $reservationname -Type Dhcp
        Set-DhcpServerv4OptionValue -ReservedIP $ip -OptionId 12 -Value $reservationname -ComputerName $DHCPServer
    
        $OptionValue1 = Get-DhcpServerv4OptionValue -ReservedIP $Ip -ComputerName $DHCPServer  # may return options 12 and 81
        Write-Host "Current Option: $($OptionValue1.Value)"
        Read-Host "Restart DHCP-Service?"
        Restart-Service DHCPServer
        sleep -Seconds 5
        $OptionValue2 = Get-DhcpServerv4OptionValue -ReservedIP $Ip -ComputerName $DHCPServer
        Write-Host "Option12 we want to set: $reservationname"
        Write-Host "Option12 after restart: $($OptionValue2.Value)"
        Read-Host "Next try?"
    }
    

2 additional answers

Sort by: Most helpful
  1. Rich Matheisen 45,091 Reputation points
    2021-06-22T19:01:27.263+00:00

    Add some error handling around that option value setting:

    Try{
        Set-DhcpServerv4OptionValue -ReservedIP $ip -OptionId 12 -Value $reservationname -ComputerName $DHCPServer -ErrorAction STOP
    }
    Catch{
        Throw $_
    }
    

    The setting of the option value requires that the option has already been defined, but I don't see that in your code (Set-DhcpServerv4OptionDefinition).
    From the help for the Set-DhcpServerv4OptionValue cmdlet: "The definition for the option must already exist."


  2. Sunny Qi 10,906 Reputation points Microsoft Vendor
    2021-06-23T09:50:14.117+00:00

    Hi,

    Thanks for posting in Q&A platform.

    I will reproduce this issue in my environment and keep you posted if any update.

    Please try to configure this Option 12 from GUI and restart to see if the issue still existed.

    Best Regards,
    Sunny

    ----------

    If the Answer is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.