locked
I'm looking for a way to purge certain NS records RRS feed

  • Question

  • Hello!

    This is the closest I've come to finding a way to display our NS record "RecordData". Basically I'm looking for a way to purge certain NS records copied over when we migrated DNS zones from one forest to another. Do you know the syntax to display record data for NS records?

    I tried this: 

    Get-DnsServerResourceRecord -ZoneName $zone -ComputerName $DNSserver -RRType "NS" | select HostName,RecordType,Timestamp,TimeToLive,@{Name='RecordData';Expression={$_.RecordData.HostNameAlias.ToString()}} | Where {$_.RecordData -match $ComputerName}

    But unfortunately the RecordData field outputted as blank.. 

    • Split by jrv Thursday, January 11, 2018 7:23 PM New question
    Thursday, January 11, 2018 6:01 PM

Answers

  • Hi,

    Based on my research, you can have a try with the following demo command to remove the NS record with specific domain name.
    Get-DnsServerResourceRecord -ZoneName contoso.com -RRType Ns | Where-Object {$_.RecordData.NameServer -like '*.abc.ca.'} | 
    Remove-DnsServerResourceRecord -ZoneName contoso.com -Confirm:$false

    If you need to do this for all zones, you can loop like this:
    Get-DnsServerZone | ForEach-Object {
        Get-DnsServerResourceRecord -ZoneName $_.ZoneName -RRType Ns | Where-Object {$_.RecordData.NameServer -like '*abc.ca.'} | 
        Remove-DnsServerResourceRecord -ZoneName $_.ZoneName -Confirm:$false
    }

    If you need further help, please feel free to let us know.

    Best Regards,
    Albert

    Please remember to mark the replies as an answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com

    Friday, January 12, 2018 7:29 AM

All replies

  • I found this thread that is very close to what Im looking for but for other record types:

    https://social.technet.microsoft.com/Forums/windowsserver/en-US/6817b151-12f3-42d5-92ae-f4f0a7e99858/querying-getdnsserversourcerecordrecorddata-ciminstanceinstance-data-in-powershell-30?forum=winserverpowershell#4df7f4a6-65ca-40c2-8aed-ec36645dc670

    Thursday, January 11, 2018 7:27 PM
  • Get-DnsServerResourceRecord -ZoneName$zone -ComputerName$DNSserver -RRType NS | Remove-DnsServerResourceRecord

    \_(ツ)_/

    Thursday, January 11, 2018 7:31 PM
  • Thanks! But this would remove no? Problem is I want to remove ones from my old forest (lests call it ABC.ca) and not the new forest name servers (lets call it XYZ.ca) 

    Ideally I would want to filter like this:

    ? {$_.Hostname -like '*abc.ca*'}|Remove-DnsServerResourceRecord

    Thursday, January 11, 2018 7:35 PM
  • So what is stopping you?  Just filter for the ones you want.


    \_(ツ)_/

    Thursday, January 11, 2018 7:40 PM
  • Sorry I should have elaborated. It doesn't work to filter basically it just comes back with "DnsServerResourceRecordNS".

    So for example If I do this:

    Get-DnsServerZone -computername DCNAME | ? {$_.zonename -like 'ZONENAME'} | Get-DnsServerResourceRecord -ComputerName DCNAME -RRType ns| select RecordData

    All that comes back is this for each record:

    RecordData
    ----------
    DnsServerResourceRecordNS
    DnsServerResourceRecordNS
    DnsServerResourceRecordNS
    DnsServerResourceRecordNS
    DnsServerResourceRecordNS
    DnsServerResourceRecordNS
    DnsServerResourceRecordNS
    DnsServerResourceRecordNS
    DnsServerResourceRecordNS
    DnsServerResourceRecordNS


    If I do this:

    Get-DnsServerResourceRecord -ZoneName ZONE -ComputerName DCNAME -RRType "ns" | select HostName,RecordType,Timestamp,TimeToLive,@{Name='RecordData';Expression={$_.RecordData.HostNameAlias.ToString()}} | Where {$_.RecordData -like $ComputerName}

    I get this for each record:

    HostName   : @
    RecordType : NS
    Timestamp  :
    TimeToLive : 01:00:00
    RecordData :

    Oddly enough if I just do this:

    Get-DnsServerResourceRecord -ZoneName ZONE -ComputerName DCNAME -RRType "ns"

    I can see the record data - 

    HostName                  RecordType Timestamp            TimeToLive      RecordData
    --------                  ---------- ---------            ----------      ----------
    @                         NS         0                    01:00:00        DC1.ABC.ca
    @                         NS         0                    01:00:00        DC2.abc.ca
    @                         NS         0                    01:00:00        DC3.abc.ca
    @                         NS         0                    01:00:00        DC4.abc.ca






    Thursday, January 11, 2018 7:55 PM
  • Hi,

    Based on my research, you can have a try with the following demo command to remove the NS record with specific domain name.
    Get-DnsServerResourceRecord -ZoneName contoso.com -RRType Ns | Where-Object {$_.RecordData.NameServer -like '*.abc.ca.'} | 
    Remove-DnsServerResourceRecord -ZoneName contoso.com -Confirm:$false

    If you need to do this for all zones, you can loop like this:
    Get-DnsServerZone | ForEach-Object {
        Get-DnsServerResourceRecord -ZoneName $_.ZoneName -RRType Ns | Where-Object {$_.RecordData.NameServer -like '*abc.ca.'} | 
        Remove-DnsServerResourceRecord -ZoneName $_.ZoneName -Confirm:$false
    }

    If you need further help, please feel free to let us know.

    Best Regards,
    Albert

    Please remember to mark the replies as an answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com

    Friday, January 12, 2018 7:29 AM
  • Thanks this seems to have worked!!
    Friday, January 12, 2018 2:38 PM