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

Centos 5.3 Server preparation for web hosting

These are compatible Repositories: FreshRPMS, Dries, NewRPMS and PlanetCCRMA   Note: to update PHP and…

NaN

- Meaning: Not a Number - When used as an assignment to an element index…

Use psexec to install application remotely

psexec @ComputerList.txt -u domain\administrator cmd /s /c "xcopy "\\NetworkPath\Forefront Software\Install.exe" "C:\Windows" && Install.exe /u /s…