Showing posts with label DNS. Show all posts
Showing posts with label DNS. Show all posts

Thursday, March 11, 2010

Query DNS with PowerShell

Following is a script that will enable you to query DNS for duplicate records. Be sure to change the location of the output file!


# Using WMI, retrieve all the duplicate DNS records
$DNS = Get-WmiObject -ComputerName 'DNS-Server' `
-Namespace 'root\MicrosoftDNS' `
-Class MicrosoftDNS_AType `
-Filter "ContainerName='Your Container'" | `
Group-Object OwnerName | Where-Object {$_.Count -gt 1}

# Create our CSV file to hold the data
$file = 'c:\temp\DNS.csv'
New-Item -ItemType file -Path $file -Force
Add-Content -Path $file -Value "Name,IPAddress"

# Iterate of the DNS items grabbing the name and IPAddress
foreach ($item in $DNS) {
foreach ($IPAddresses in $item.Group) {
$value = "{0},{1}" -f $item.name,$IPAddresses.IPAddress
Add-Content -Path $file -Value $value
}
}

Results should look something like:

NameIPAddress
Server110.194.111.22
Server210.140.111.22
ServerA10.333.19.121
ServerB10.333.131.24

Enjoy!

Wednesday, June 18, 2008

Change DNS/WINS IP on Multiple Servers

I was recently asked if I could change the DNS & WINS IP address on multiple servers via script. PowerShell to the rescue! After a brief search, I found a great post. Following is my implementation.

function Set-DNSWINS {
#Get NICS via WMI
$NICs = Get-WmiObject '
-Class Win32_NetworkAdapterConfiguration '
-ComputerName $_ '
-Filter "IPEnabled=TRUE"

foreach($NIC in $NICs) {
$DNSServers = "12.34.5.67","76.54.3.21"
$NIC.SetDNSServerSearchOrder($DNSServers)
$NIC.SetDynamicDNSRegistration("TRUE")
$NIC.SetWINSServer("12.345.67.890", "12.345.67.891")
}
}

function Get-FileName {
$computer = Read-Host "Filename of computer names?"
return $computer
}

$f = Get-FileName
Get-Content $f foreach {Set-DNSWINS}

Gotta love PowerShell!