top of page

PowerShell | Mass Update DNS Settings

Using multiple DNS IP settings on a network in a Windows domain provides several benefits that enhance the reliability, performance, and management of network resources. Here’s a detailed explanation of why and how multiple DNS IP settings are used in such environments:

​

Benefits of Using Multiple DNS IP Settings

  1. Redundancy and High Availability:

    • Fault Tolerance: Having multiple DNS servers ensures that if one server becomes unavailable due to maintenance, failure, or network issues, other DNS servers can still resolve domain names, preventing downtime.

    • Load Balancing: Distributing DNS queries across multiple servers can balance the load, preventing any single server from being overwhelmed, especially during peak usage times.

  2. Improved Performance:

    • Geographical Distribution: In large or geographically distributed networks, having DNS servers in different locations can reduce latency, as clients can connect to the nearest DNS server.

    • Caching Efficiency: Multiple DNS servers can cache different queries, improving response times for DNS lookups by reducing the need for repeated queries to external DNS servers.

  3. Network Management and Scalability:

    • Segmentation: Different DNS servers can be configured to handle specific subdomains or segments of the network, making it easier to manage large networks.

    • Scalability: Adding additional DNS servers allows the network to scale more easily, accommodating growth in the number of users and devices.

PowerShell Script Mass Update DNS Settings

​<#

Set DNS Server List on Variable $newDNSServers

Any NIC with DNS Gets New DNS Settings

#>

#======================

#Get List of Computers

#======================

$MyComputers = Get-ADComputer -filter * -Properties * | Where { ($_.Enabled -eq $True) -and ($_.Operatingsystem -like "Windows*") } | Select -ExpandProperty Name 

#====================

#Instantiate Array

#===================

$MyArray = @()

$MyFails = @()

#===============================

#Check Access to Each Computer

#===============================

Foreach ($Comp in $MyComputers) {       

    If ((Invoke-Command -ErrorAction SilentlyContinue –ComputerName $comp –ScriptBlock { 1 }) –eq 1) {

        $MyArray += $Comp

    }

    Else {

        $MyFails += $Comp

    }

}

#====================================================

# Export Pass failed for Further Review

#====================================================

$MyArray | Out-File C:\temp\PassedDNSSystems.txt

$MyFails | Out-File C:\temp\FailedDNSSystems.txt

#====================================================

# -------Main Command Execute on Remote Machines---------

#====================================================

$MyCommand = {

    # Update Double Quoted and Commma Separated DNS Servers by IP

    $newDNSServers = "127.0.0.1", "192.168.254.254"

    # Get all network adapters that already have DNS servers set

    $adapters = Get-WmiObject Win32_NetworkAdapterConfiguration | Where-Object { $_.DNSServerSearchOrder -ne $null }

    # Set the DNS server search order for all of the previously-found adapters

    $adapters | ForEach-Object { $_.SetDNSServerSearchOrder($newDNSServers) }

    #Get New DNS Settings and Return in Object

    $MyNS = Get-WmiObject Win32_NetworkAdapterConfiguration | Where-Object { ($_.DNSServerSearchOrder -ne $null) } | Select -ExpandProperty DNSServerSearchOrder

    #===================================

    # Pull DNS Settings add to Object

    #===================================

    $Obj = New-Object PSObject

    $Obj | Add-Member NoteProperty ServerName ($env:COMPUTERNAME)

    $Obj | Add-Member NoteProperty DNS_Settings ($MyNS)

    Return $Obj

} # End Main Command

#===============================================

# ------ Execution & Export to File ------------

#===============================================

$MyReturnValues = Invoke-Command $MyArray -ScriptBlock $MyCommand

$MyReturnValues | Select ServerName, DNS_Settings | Where { $_.ServerName -ne $NULL } | Export-Csv C:\temp\NewDNS.csv -NoTypeInformation -Append

How Multiple DNS IP Settings Work

Primary and Secondary DNS Servers

In a typical configuration, you have primary and secondary DNS servers specified in the network settings.

  1. Primary DNS Server:

    • The first server that a client contacts for DNS resolution. It is usually the most reliable and fastest option available.

  2. Secondary DNS Server:

    • Acts as a backup in case the primary DNS server is unavailable. It takes over DNS resolution if the primary server fails to respond within a specified timeout period.

bottom of page