Created
July 29, 2025 14:28
-
-
Save Apoc70/5ed99af6fc94aba3b8c26376c31d741d to your computer and use it in GitHub Desktop.
Set RegisterThisConnectionsAddress for primary network adapter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| get network adapters with status UP (1) | |
| $adapters = Get-NetAdapter | Where-Object { | |
| $_.InterfaceOperationalStatus -eq 1 | |
| } | |
| # sort adapters and select primary adapter (lowest metrik) | |
| $primaryAdapter = $adapters | Sort-Object InterfaceIndex | Select-Object -First 1 | |
| # get DNS client settings | |
| $dnsClient = Get-DnsClient | Where-Object { $_.Interfaceindex -eq $primaryAdapter.Interfaceindex } | |
| if ($dnsClient.RegisterThisConnectionsAddress -eq $false) { | |
| Write-Host ('Setting RegisterThisConnectionsAddress to TRUE for {0}' -f $dnsClient.InterfaceAlias) | |
| } | |
| else { | |
| Write-Host 'Nothing to change.' | |
| } | |
| # THIS CODE IS MADE AVAILABLE AS IS, WITHOUT WARRANTY OF ANY KIND. THE ENTIRE | |
| # RISK OF THE USE OR THE RESULTS FROM THE USE OF THIS CODE REMAINS WITH THE USER. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment