Retrieving DNS Info With PowerShell
27 Oct 2016I had reason to iterate over all the web sites that we host to determine which domains we host the DNS for. I did some Googling and found a PowerShell script that I heavily modified to come up with the following:
$name = "heat-assault.com"
try{
$dns = Resolve-DnsName -Name $name -Type NS -DnsOnly -ErrorAction Stop
$IPhash = @{}
$dnsHostName = ($dns | Where-Object Section -ne Additional | Select-Object -first 1).NameHost
if ($dnsHostName -like '*canadawebhosting*')
{
Write-Host "CWH"
} else {
Write "Nope - " $dnsHostName
}
} Catch{
[pscustomobject]@{
Name = $name
NameHost = ''
IP = ''
Status = $Error[0].Exception.Message
}
}