In most environments, an admin usually just jumps on the server that they need to work from and does their work from there. An example of this would be an admin working on an IIS Web server and needing to remove a DNS A record from DNS without having to logon to the DNS server itself so that they can quickly make their changes in IIS.
A quick way to do this would be to run the following ps1 script in PowerShell in order to be able to remove the record quickly:
1 2 3 4 5 6 7 8 9 10 11 | $NodeToDelete = Read-Host "Please Input the Name of the A Record you want to delete. NO FQDN" $DNSServer = Read-Host "Please Input your DNS Server FQDN" $ZoneName = Read-Host "Please Input the DNS Zone the A Record is residing in" $NodeDNS = $null $NodeDNS = Get-DnsServerResourceRecord -ZoneName $ZoneName -ComputerName $DNSServer -Node $NodeToDelete -RRType A -ErrorAction SilentlyContinue if($NodeDNS -eq $null){ Write-Host "The DNS A Record You Were Looking For Was Not Found" -ForeGroundColor Red } else { Remove-DnsServerResourceRecord -ZoneName $ZoneName -ComputerName $DNSServer -InputObject $NodeDNS -Force Write-Host "Your DNS A Record $NodeToDelete Has Been Removed" -ForeGroundColor Green } |
Now this works for a single DNS A Record. If there are multiple IPs for the same DNS record, for example, test.ldlnet.local points to both 192.168.1.23 and 192.168.1.24, then you probably need to run the following script listed here to keep the script from failing with an error. I have also expanded the entries to help the input be more specific:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | Write-Host "This script will remove a DNS Record based on the information provided" -ForegroundColor Yellow Write-Host "There can be multiple Host Records (IPs) for a given Host Name. Only one Record going with the matching IP address that is input will be deleted" -ForegroundColor Red Write-Host "For Example: In the ldlnet.org zone there are two records test.ldlnet.org > 192.168.1.23 and test.ldlnet.org > 192.168.1.24. This action removes only one of the entries of test.ldlnet.org, matching the IP address that was input." -ForegroundColor Red $NodeToDelete = Read-Host "Please Input the Name of the DNS Record you want to delete. (NO FQDN)" $DNSServer = Read-Host "Please Input your DNS Server FQDN" $ZoneName = Read-Host "Please Input the DNS Zone the DNS Record is residing in" $RecordType = Read-Host "Please Input the Type of DNS Record It Is (A, CNAME, TXT, etc...)" $IP = Read-Host "Please Input the IP Address of the Associcated DNS Record" $NodeDNS = $null $NodeDNS = Get-DnsServerResourceRecord -ZoneName $ZoneName -ComputerName $DNSServer -Node $NodeToDelete -RRType $RecordType -ErrorAction SilentlyContinue if($NodeDNS -eq $null){ Write-Host "The DNS A Record You Were Looking For Was Not Found" -ForeGroundColor Red } else { Remove-DnsServerResourceRecord -ZoneName $ZoneName -ComputerName $DNSServer -RecordData $IP -Name $NodeToDelete -RRType $RecordType -Force -ErrorAction Stop Write-Host "Your DNS A Record $NodeToDelete Has Been Removed" -ForeGroundColor Green } |
I have found some other good scripts that I will post to the blog to help manage DNS records through PowerShell. This should get things started for now. Happy Troubleshooting!