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

How To Remove A Program on Windows Using PowerShell

# removeAppwizProgram.ps1 # Version 0.02 $computernames=@( 'SERVER0001', 'SERVER0002' ) $appName='Dell EMC OpenManage Systems Management Software…

Basic CSS: Style Multiple Elements with a CSS Class

<style>.red-text {color: red;}</style><h2 class="red-text">CatPhotoApp</h2><main><p>Click here to view more <a href="#">cat photos</a>.</p><a href="#"><img src="https://bit.ly/fcc-relaxing-cat" alt="A cute…

WordPress: Add Search Box Into Header

Navigate to Appearance > Theme Editor > select header.php > search for this section: <div…