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

Windows 2012: How To Install DotNet Framework 2.0 & 3.0

If there're HTTPS/TLS issues, run this function: https://blog.kimconnect.com/powershell-enable-tls-1-2-on-legacy-servers/ Toggle WSUS registry key to off prior…

Excel Challenge: Update Records with a New Email Domain if It Matches Deprecated Domain

PrimaryEmail (Cell B2) EmailUsername Domain [email protected] =LEFT(B2,FIND("@",B2)-1) =RIGHT(B2,LEN(B2)-FIND("@",B2)) FixedPrimaryEmail =IF(D2="olddomain.org",C2&"@newdomain.org",B2)

PowerShell: Replicate All Domain Controllers Immediately

<#Author: KimConnect.comVersion: 0.1Purpose:- After a change has been issued against a "logon server", that domain…