none
Looking for a command to delete mx record from DNS RRS feed

  • Question

  • Hello,

    I'm currently writing scripts to manage our public DNS Server but i'm now blocking on a script to delete mx record.

    let's say i have a domain contoso.com

    i have 2 mx Records for contoso.com

    one with preference 10 pointing on mail1.contoso.com

    and one with preference 20 pointing on mail2.contoso.com

    if i use this command line :

    Remove-DnsServerResourceRecord -ZoneName "contoso.com" -RRType "MX" -Name "@"  -Force


    i can delete the two MX records at once

    But i would like to be able to choose witch MX Record i want to delete.

    i tried this command to delete the second MX record:

    Remove-DnsServerResourceRecord -ZoneName "contoso.com" -RRType "MX" -Name "@" -RecordData "mail2.contoso.com"  -Force


    but it ends with an error 

    InputObject for resource record has an invalid value. Failed to remove the resource record on dns1.contoso.com server. Please check extended error for additional details.
        + CategoryInfo          : InvalidData: (dns1.contoso.com:root/Microsoft/...rResourceRecord) [Remove-DnsServerResourceRecord], CimException
        + FullyQualifiedErrorId : WIN32 13,Remove-DnsServerResourceRecord
        + PSComputerName        : 10.0.0.10

    has anyone an idea that could help ?

    Thank you 

    StephaneDe


    Monday, March 23, 2015 3:57 PM

Answers

  • Get-DnsServerResourceRecord -ZoneName contoso.com -Name "@" -RRType Mx |
        Where-Object {$_.RecordData.Preference -eq 20 -and $_.RecordData.MailExchange -eq 'mail2.contoso.com.'} |
        Remove-DnsServerResourceRecord -ZoneName contoso.com

    • Marked as answer by StephaneDe Tuesday, March 24, 2015 4:13 PM
    Monday, March 23, 2015 7:54 PM

All replies

  • Get-DnsServerResourceRecord -ZoneName contoso.com -Name "@" -RRType Mx |
        Where-Object {$_.RecordData.Preference -eq 20 -and $_.RecordData.MailExchange -eq 'mail2.contoso.com.'} |
        Remove-DnsServerResourceRecord -ZoneName contoso.com

    • Marked as answer by StephaneDe Tuesday, March 24, 2015 4:13 PM
    Monday, March 23, 2015 7:54 PM
  • Thank your,

    i'm new to powershell scripting and i learned new things.

    Thank you very much.

    Stephanede

    Tuesday, March 24, 2015 4:13 PM