Posted On November 4, 2020

PowerShell: Set DNS Server IPs on Default Network Interface

kimconnect 0 comments
blog.KimConnect.com >> Codes >> PowerShell: Set DNS Server IPs on Default Network Interface
$dns1=.{
    Import-Module ActiveDirectory
    $fsmoRoles=Get-ADDomainController -Filter *|Select-Object Name, Domain, Forest, OperationMasterRoles|Where-Object {$_.OperationMasterRoles}|select Name,OperationMasterRoles
    $pdcServer=($fsmoRoles|?{'PDCEmulator' -in $_.OperationMasterRoles}).Name
    return [system.net.dns]::GetHostByName($pdcServer).AddressList.IpaddressToString|select -first 1
}
$dns2='8.8.8.8'

$defaultInterface=get-wmiobject win32_networkadapterconfiguration -filter "ipenabled='true'"|?{$_.DefaultIpGateway -ne $null}
Set-DnsClientServerAddress -InterfaceIndex $defaultInterface.Index -ServerAddresses @($dns1,$dns2)
Register-DnsClient

Leave a Reply

Your email address will not be published. Required fields are marked *

Related Post

Install and Remove Choco Applications As Well As Application Wizard Programs

# installChocoApps.ps1 [string[]]$computers=@( 'SERVER01', 'SERVER02', 'SERVER03' ) [string]$chocoAppName='pgadmin4' [version]$minVersion='6.0' function installChocoApp{ param( [string[]]$computers=$env:computername, [string]$chocoAppName='Firefox', [version]$minVersion='7.0'…

How To Format HTML Content For Email

Major email service providers such as Google Gmail and Microsoft Office 365 have been supporting…

How to Add Domain Admins to SQL Server

Step 1: Right-click Start > Search > type in 'ssms.exe' > right-click Microsoft SQL Server…