$NETAdapters = netsh interface ipv4 show dnsservers $filteredAdapters = @() $Output = @() $currentInterface = "" foreach ($line in $NETAdapters) { if ($line -match 'Configuration for interface "(.*)"') { $currentInterface = $matches[1] } elseif ($currentInterface -ne "" -and $line -match "127.0.0.1") { $filteredAdapters += $currentInterface $currentInterface = "" } } $Interfacepath = @( "HKLM:\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces", "HKLM:\SYSTEM\CurrentControlSet\Services\Tcpip6\Parameters\Interfaces" ) $filteredInterfaces = @() foreach ($path in $Interfacepath) { $Interfaces = Get-ChildItem -Path $path foreach ($interface in $Interfaces) { if ((Get-ItemProperty -Path $interface.PSPath).PSObject.Properties.Name -contains "NameServer") { $interfaceValue = Get-ItemPropertyValue -Path $interface.PSPath -Name 'NameServer' if ($interfaceValue -eq '127.0.0.1') { $filteredInterfaces += $interface.PSChildName } } } } if ($filteredAdapters.Count -gt 0) { $Output += "FOUND LOCALHOST DNS ENTRIES FOR $filteredAdapters" } if ($filteredInterfaces.Count -gt 0) { $Output += "FOUND REGISTRY DNS ENTRIES FOR $filteredInterfaces" } if ($Output.Count -gt 0) { Write-Output $Output Exit 1 } Else { Write-Output "No Issues Detected" Exit 0 }