Skip to content

Instantly share code, notes, and snippets.

@Apoc70
Created July 29, 2025 14:28
Show Gist options
  • Select an option

  • Save Apoc70/5ed99af6fc94aba3b8c26376c31d741d to your computer and use it in GitHub Desktop.

Select an option

Save Apoc70/5ed99af6fc94aba3b8c26376c31d741d to your computer and use it in GitHub Desktop.
Set RegisterThisConnectionsAddress for primary network adapter
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