NetworkingDsc
NetworkingDsc copied to clipboard
xDnsServerAddress does not allow clearing of primary/secondary DNS Address
Address has a ValidateNotNullOrEmpty attribute however it's a valid operation to clear it. If using DHCP then the manual address would be set back to automatic (just like the GUI). If using a static IP, then the manual addresses would be cleared.
When empty it should use the following cmdlet Set-DnsClientServerAddress -InterfaceAlias "Ethernet" -ResetServerAddresses This mimics the Windows UI functionality in that if DHCP is enabled DNS is set to automatic, if static IP is enabled the DNS is set to blank manual address (windows still technically classes this as automatic).
Hi @andy1547 - thanks for raising this!
I have battled with this problem for a while now and I've tried to sum up the problem in this issue: https://github.com/PowerShell/xNetworking/issues/113
I think it actually requires a change to the PowerShell cmdlets to expose whether or not DHCP is enabled on the DNS Client itself - which is currently not visible at all the PowerShell.
Hi @andy1547 - I've completed the changes for this and am just waiting for a review to merge into the Dev branch. But if you're up for it you could test my version here: https://github.com/PlagueHO/xNetworking/tree/Issue-113
Thanks!
@PlagueHO Having a skim over this it looks great so far, will hopefully get a chance to test some week sometime (deadlines are pretty tight over here). Thanks!
Thanks @andy1547 - this change has now been merged into Dev. So you can try it on the dev branch now.
Will test this week, thanks @PlagueHO
Hi @andy1547 - did you get a chance to check this one? Did it work OK? If so, can we close this one?
Sorry @PlagueHO been a busy free months!
Managed to test this today and worked as expected. Tested the standard use cases and the following edge cases with IPv4:
- 3+ dns servers.
- clearing the DNS servers both with DHCP enabled and disabled.
The only thing thing I noticed is an empty array is not permitted to clear the DNS servers, ideally an empty array would clear but null would leave as is.
Great work though, thanks!
Hi @andy1547 - sorry I forgot to respond to this one. But actually, it does look like we should be able to accept an empty array for Address
. If you don't specify an Address
parameter at all, internally it sets $Address
to an empty array anyway. So I'll hold this open so we can consider making this enhancement.
Thanks!
If anyone else has the same problem to detect if the dns servers are static or from dhcp:
netsh interface ipv4 show dns
netsh interface ipv6 show dns
there is no known other ("better") api, event wmi documentation does not state anything.
When empty it should use the following cmdlet Set-DnsClientServerAddress -InterfaceAlias "Ethernet" -ResetServerAddresses This mimics the Windows UI functionality in that if DHCP is enabled DNS is set to automatic, if static IP is enabled the DNS is set to blank manual address (windows still technically classes this as automatic).
This functionality is available in DnsServerAddress.
@PlagueHO - I believe this issue can be closed.