Disclaimer / Clause de non-responsabilité / Haftungsausschluss:
Use of the code examples is at your own risk!
L’utilisation des exemples de code s’effectue à vos propres risques et périls !
Die Nutzung der Codebeispiele erfolgt auf eigenes Risiko!
The idea here is to reset the DNS servers on all physical Ethernet and WLAN adapters so that they are obtained automatically again.
The name of the WLAN adapter is determined automatically.
<#
Owner: marcel.powershell@use.startmail.com
Disclaimer: Use of the code examples is at your own risk!
Network Interface Type 71 is a Wireless80211 device:
https://learn.microsoft.com/en-us/dotnet/api/system.net.networkinformation.networkinterfacetype?view=net-5.0
$WlanType = [int][System.Net.NetworkInformation.NetworkInterfaceType]::Wireless80211
FullReset: Get-DnsClientServerAddress | Set-DnsClientServerAddress -ResetServerAddresses
#>
#
# Set Variables
#
$WlanType = 71
cls
write-host
Write-Host "*_* Local DNS Server Reset! (IPv4 & IPv6 - Wi-Fi and Physical Ethernet Network Adapters)"
Write-Host
#
# Query WLAN-Adaptername & Interfaceindex
#
$WlanAdapterName = (Get-NetAdapter | Where-Object InterfaceType -eq $WlanType).Name
$WlanIntIndex = (Get-NetAdapter -Name "$WlanAdapterName").ifIndex
#
# Reset all Physical Ethernet Adapters
#
Get-NetAdapter -Name "Ethernet*" -Physical | Set-DnsClientServerAddress -ErrorAction SilentlyContinue -ResetServerAddresses
#
# Reset WiFi Adapter
#
Set-DnsClientServerAddress -InterfaceIndex $WlanIntIndex -ErrorAction SilentlyContinue -ResetServerAddresses
#
# Done Report
#
write-host "-"
Write-host "... done!"
Write-Host
#
# Show Affected Adapters
#
$EthernetAdapter = Get-NetAdapter -Name "Ethernet*" -Physical | Out-String
$WlanAdapter = Get-NetAdapter -Name "$WlanAdapterName" | Out-String
Write-Host $EthernetAdapter -ForegroundColor DarkYellow
Write-Host "($WlanType $WlanAdapterName $WlanIntIndex)" -ForegroundColor DarkCyan
Write-Host $WlanAdapter -ForegroundColor DarkYellow
Write-Host "-"
pause