473,406 Members | 2,843 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes and contribute your articles to a community of 473,406 developers and data experts.

DNS Server - PowerShell - Domain Controller Removal from Name Servers

300 256MB
All,
As I head through a major refresh I realized it was way too cumbersome to manually remove decommissioned domain controllers from the 'Name Servers' tab inside of DNS forward and reverse lookup zones. I came up with the below script to automate the removal of these records. I hope this helps others in the future.

All you need to do is modify the FQDN (Fully Qualified Domain Name) on Line 2.

Expand|Select|Wrap|Line Numbers
  1.         #FQDN of the domain controller that has been decommissioned or is offline
  2.         $oldDMCName = "DMC1.domain.org"
  3.  
  4.         #Get the PDC Emulator
  5.         $PDCe = Get-ADDomainController -Discover -Service PrimaryDC
  6.  
  7.         #Get all DNS zones on the PDCe
  8.         $DNSZones = Get-DnsServerZone -ComputerName $PDCe
  9.  
  10.         #Iterate DNS zones and remove the stale domain controller record where applicable
  11.         ForEach($zone in $DNSZones)
  12.           {
  13.             $zone = $zone.zoneName
  14.             $getZoneInfo2 = (Get-DnsServerResourceRecord -ZoneName $zone -Name "@" -RRType NS -ComputerName $PDCe).recorddata.nameserver
  15.             If($getZoneInfo -like "*$oldDMCName*")
  16.               {
  17.                 Try
  18.                   {
  19.                     Remove-DNSServerResourceRecord -ZoneName $zone –Name “@” –RRType NS –RecordData $oldDMCName -ComputerName $PDCe -Force
  20.                   }
  21.                 Catch
  22.                   {
  23.                     Write-Output "Error removing $oldDMCName from $zone"
  24.                   }
  25.               }
  26.             Else
  27.               {
  28.                 Write-Output "$oldDMCName does not exist in zone $zone"
  29.               }
  30.           }
Apr 26 '16 #1
1 19535
great man, that's amazing question to ask
Aug 17 '23 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Douglas G. Walker | last post by:
Can anyone tell me how to get ASP to work on a Server 2003 domain controller? I keep getting 10004 errors in the system log. I've tried resynching passwords etc.
2
by: Frank | last post by:
I have observed that a temporary loss of a domain controller can cause problems creating new ado connections between a client machine running ado and a separate sql server machine that are members...
1
by: Michael Maes | last post by:
Hello, I can't get the ASPNET-Account installed on a Windows 2000 (5.00.2195) Server SP4 Domain Controller. I always receive "Web Server not running ASP.NET version 1.1" when I try to start a...
3
by: Richard Chandler | last post by:
We're having a problem with ASP.NET security and running on a Win2k Domain Controller. We can't set up the access rights to the registry for ASPNET as the user doesn't exist, this access is...
13
by: | last post by:
Hi all, I'm having some problems after upgrading a windows 2000 Server to Domain Controller. Symptoms: every aspx page returns blank HTTP Response headers: HTTP/1.0 200 OK Server:...
0
by: Richard | last post by:
First some background... I have an application whereby I send a mail, attach some attachments stored in the windows/temp directory and then send them. This works fine on 2 servers both are not...
1
by: SL | last post by:
How do I set up access to a file on a Windows Server 2003 Domain Controller that also has IIS? The file sits on another server. The Domain Controller / IIS server connects to this file through a...
0
by: Rob Roberts | last post by:
I have developed an ASP.NET 2.0 application using localhost on my Windows XP workstation, and it all works fine there. I tried to copy it to my test web server, which is a domain controller...
1
by: Kazmataz | last post by:
Hi, I have set my .net application to impersonate and is installed on a Web Farm of 4 servers. In this application I allow users to upload files to the server. I have it setup so that no matter...
0
by: SandVich | last post by:
i had two servers with Windows2000 Advance server OS. One is main Domain Controller and second on is additional. A problem occurred in additional domain controller and ultimately i had to format...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.