Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DhcpServerOptionValue: DNS Option Fails due to no 'Force' attribute #56

Closed
tagur87 opened this issue Jan 14, 2019 · 8 comments · Fixed by #78
Closed

DhcpServerOptionValue: DNS Option Fails due to no 'Force' attribute #56

tagur87 opened this issue Jan 14, 2019 · 8 comments · Fixed by #78
Labels
needs more information The issue needs more information from the author or the community.

Comments

@tagur87
Copy link

tagur87 commented Jan 14, 2019

Details of the scenario you tried and the problem that is occurring

When using the DhcpServerOptionValue resource to install DNS servers for the whole DHCP server, it fails when the DNS servers are not resolvable.

Just as when installing DNS servers via the GUI, it checks for the IP addresses to be resolvable. But due to different test scenarios or other scenarios where the DNS servers wouldn't be accessible, it fails when it cannot resolve the IP's.

Verbose logs showing the problem

PowerShell Cmdlet failed: 10.1.1.1 is not a valid DNS server.
+ CategoryInfo : InvalidArgument: (ZADHCP003:) [], CimException
+ FullyQualifiedErrorId : WIN32 87,Set-DhcpServerv4OptionValue
+ PSComputerName : localhost

   The PowerShell DSC resource '[DhcpServerOptionValue]DirectResourceAccess' with SourceInfo '' threw one or more
   non-terminating errors while running the Set-TargetResource functionality. These errors are logged to the ETW channel
   called Microsoft-Windows-DSC/Operational. Refer to this channel for more details.
       + CategoryInfo          : InvalidOperation: (root/Microsoft/...gurationManager:String) [], CimException
       + FullyQualifiedErrorId : NonTerminatingErrorFromProvider
       + PSComputerName        : localhost

Suggested solution to the issue

Add an optional -Force setting to allow for forcing the setting when the option isn't valid at this time.

The DSC configuration that is used to reproduce the issue (as detailed as possible)

configuration Sample_DhcpServerOptionValue_SetOption
{
    Import-DscResource -module xDHCpServer
    DhcpServerOptionValue DNSSettings
{
        Ensure = 'Present'
        OptionId = 6
        Value = '10.1.1.1', '10.2.2.2', '10.3.3.3'
        VendorClass = ''
        AddressFamily = 'IPv4'
        UserClass = ''
    }
}

The operating system the target node is running

OsName : Microsoft Windows Server 2016 Datacenter
OsOperatingSystemSKU : DatacenterServerEdition
OsArchitecture : 64-bit
WindowsBuildLabEx : 14393.2665.amd64fre.rs1_release.181203-1755
OsLanguage : en-US
OsMuiLanguages : {en-US}

Version and build of PowerShell the target node is running

PSVersion 5.1.14393.2636
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.14393.2636
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1

Version of the DSC module that was used ('dev' if using current dev branch)

2.0.0.0

@tagur87
Copy link
Author

tagur87 commented Jan 14, 2019

Hi @johlju & @PlagueHO !

Sorry to bug you, but I was just curious how hard it would be to implement this issue request. I would work on it, but I am not familiar enough with the setup of a DSC resource to know the best way to implement this.

If either of you have time to look at this, I would be very grateful! :)

@johlju
Copy link
Member

johlju commented Jan 15, 2019

I think you need to do this - rough list

Note that the helper updates all the *option* resources so you might need to make sure the new parameter work in all of those as well.

If you have any problems along the way, then please ask away here. We are happy to help.

@stale
Copy link

stale bot commented Feb 14, 2019

This issue has been automatically marked as stale because it has not had activity from the community in the last 30 days. It will be closed if no further activity occurs within 10 days. If the issue is labelled with any of the work labels (e.g bug, enhancement, documentation, or tests) then the issue will not auto-close.

@stale stale bot added the stale The issue or pull request was marked as stale because there hasn't been activity from the community. label Feb 14, 2019
@johlju johlju added bug The issue is a bug. help wanted The issue is up for grabs for anyone in the community. and removed stale The issue or pull request was marked as stale because there hasn't been activity from the community. labels Mar 1, 2020
@dahifi
Copy link

dahifi commented Jul 28, 2020

I'm running into something similar on a fresh Azure 2016 server I'm using for testing.

configuration DHCPServer
{
    Import-DscResource -ModuleName PSDscResources
    Import-DscResource -moduleName xDhcpServer
    WindowsFeature DHCP
    {
       Name = 'DHCP'
       Ensure = 'Present'
    }
    WindowsFeature 'RSAT-DHCP'
    {
       Name = 'RSAT-DHCP'
       Ensure = 'Present'
    }

    # Setting scope gateway
    DhcpScopeOptionValue scopeOptionGateway
    {
        OptionId = 3
        Value = '10.0.0.1'
        ScopeId =   '1.1.1.0'
        VendorClass = ''
        UserClass   = ''
        AddressFamily = 'IPv4'
    }

    # Setting scope DNS servers
    DhcpScopeOptionValue scopeOptionDNS
    {
        OptionId = 6
        Value = '10.0.0.4'
        ScopeId =   '1.1.1.0'
        VendorClass = ''
        UserClass   = ''
        AddressFamily = 'IPv4'
    }

    # Setting scope DNS domain name
    DhcpScopeOptionValue scopeOptionDNSDomainName
    {
        OptionId = 15
        Value = 'contoso.com'
        ScopeId =   '1.1.1.0'
        VendorClass = ''
        UserClass   = ''
        AddressFamily = 'IPv4'
    }

    xDhcpServerAuthorization 'LocalServerActivation'
    {
        # IsSingleInstance = 'Yes'
        Ensure           = 'Present'
    }

    xDhcpServerScope 'Scope'
    {
        Ensure        = 'Present'
        ScopeId       = '10.0.0.0'
        IPStartRange  = '10.0.0.100'
        IPEndRange    = '10.0.0.254'
        Name          = 'ContosoScope'
        SubnetMask    = '255.255.255.0'
        LeaseDuration = ((New-TimeSpan -Hours 8).ToString())
        State         = 'Active'
        AddressFamily = 'IPv4'
    }
}

Starts failing for all of the DHCPScopeOptionValues:

VERBOSE: [oadb-dc01]:                            [[DhcpScopeOptionValue]scopeOptionGateway] Getting DHCP scope option value "3" with vendor class ""
 and user class "" and Scope ID "1.1.1.0".
Failed to get option values on DHCP server oadb-dc01.
    + CategoryInfo          : ObjectNotFound: (oadb-dc01:) [], CimException
    + FullyQualifiedErrorId : DHCP 20005,Get-DhcpServerv4OptionValue
    + PSComputerName        : localhost
 
VERBOSE: [oadb-dc01]:                            [[DhcpScopeOptionValue]scopeOptionGateway] DHCP server option value "3" with vendor class "" and us
er class "" and scope ID "1.1.1.0" not found.
VERBOSE: [oadb-dc01]: LCM:  [ End    Test     ]  [[DhcpScopeOptionValue]scopeOptionGateway]  in 0.3590 seconds.
The PowerShell DSC resource '[DhcpScopeOptionValue]scopeOptionGateway' with SourceInfo 
'C:\Users\cmitadmin\Documents\dhcp.ps1::17::5::DhcpScopeOptionValue' threw one or more non-terminating errors while running the 
Test-TargetResource functionality. These errors are logged to the ETW channel called Microsoft-Windows-DSC/Operational. Refer to this channel for 
more details.
    + CategoryInfo          : InvalidOperation: (:) [], CimException
    + FullyQualifiedErrorId : NonTerminatingErrorFromProvider
    + PSComputerName        : localhost

Repeat for option 6, option 15.

@realslacker
Copy link
Contributor

I think the default action on this should to ALWAYS call force. If you are asserting a value with DSC server side validation should not be going on. Configuration should be applied as defined in config, even if it's wrong.

realslacker added a commit to realslacker/xDhcpServer that referenced this issue Mar 5, 2021
realslacker added a commit to realslacker/xDhcpServer that referenced this issue Mar 5, 2021
Update CHANGELOG for resolution to issue dsccommunity#56
@johlju
Copy link
Member

johlju commented May 6, 2022

According to the documentation the Force parameter is only applicable when the DnsServer parameter is specified.

Specifies that the DNS server validation is skipped. This parameter is only applicable if the DnsServer parameter is specified.
https://docs.microsoft.com/en-us/powershell/module/dhcpserver/set-dhcpserverv4optionvalue?view=windowsserver2022-ps

@johlju
Copy link
Member

johlju commented May 6, 2022

Has someone verified that adding -Force as per PR #78 do work since the docs (referred to in #56 (comment)) say that it should not? 🤔

@johlju johlju added needs more information The issue needs more information from the author or the community. and removed bug The issue is a bug. help wanted The issue is up for grabs for anyone in the community. labels May 6, 2022
@jangins101
Copy link

I'm running into this same issue and would love to see the -Force options be implemented (even if it required specifying a Force property in the DSC configuration).

As the request here is for more information, I went in an tested the Set-DhcpServerv4OptionValue cmdlet using a couple different options to see if the -Force would have any unexpected result. I tested with options 3, 6 & 15. The only one I saw fail was 6 (DNS Server), stating "[ip address] is not a valid DNS server.". With the -Force flag, the same command was successful. This was without specifying a DnsServer property on the cmdlet. The exact command used was Set-DhcpServerv4OptionValue -ScopeId 'x.x.x.x' -OptionId 6 -Value @('y.y.y.y','z.z.z.z') -VendorClass '' -UserClass '' -Force.

I also tested a DHCP configuration file on a server with the code changes mentioned with PR #78. This resulted in a successful update of the settings that were previously failing. Nothing new failed as a result of this either.

Hope this helps with the needs more information tag. Happy to help some more if necessary.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs more information The issue needs more information from the author or the community.
Projects
None yet
5 participants