Looking for a command to delete mx record from DNS

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


March 23rd, 2015 12:00pm

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

Free Windows Admin Tool Kit Click here and download it now
March 23rd, 2015 3:57pm

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 14 hours 54 minutes ago
March 23rd, 2015 7:54pm

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
Free Windows Admin Tool Kit Click here and download it now
March 23rd, 2015 7:54pm

Thank your,

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

Thank you very much.

Stephanede

March 24th, 2015 12:14pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics