SOLVED

How can I query Exchange Online for the generated MX record for each of my domains?

%3CLINGO-SUB%20id%3D%22lingo-sub-205926%22%20slang%3D%22en-US%22%3EHow%20can%20I%20query%20Exchange%20Online%20for%20the%20generated%20MX%20record%20for%20each%20of%20my%20domains%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-205926%22%20slang%3D%22en-US%22%3E%3CP%3EIs%20it%20possible%20to%20read%20the%20generated%20MX%20record%20for%20each%20Email%20domain%20in%20Exchange%20Online%20anywhere%20except%20on%20the%20Admin%20Portal%3F%20For%20example%20in%20Powershell%3F%3C%2FP%3E%3CP%3EMore%20specifically%20I%20am%20talking%20about%20the%20MX%20record%20that%20I'm%20supposed%20to%20set%20on%20my%20domain%20in%20order%20to%20be%20able%20to%20receive%20email.%3C%2FP%3E%3CP%3EI%20can%20see%20it%20on%20the%20Admin%20Portal%2C%20but%20I%20want%20to%20be%20able%20to%20query%20it%20somehow.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThe%20reason%20for%20this%20is%20that%20I%20need%20to%20be%20able%20to%20make%20a%20monitoring%20service%20for%20the%20several%20hundred%20MX%20records%20for%20my%20customers'%20domains.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ESo%20far%2C%20I've%20been%20able%20to%20list%20all%20the%20domains%20of%20all%20my%20Tenants%20with%20the%20Powershell%20MSOnline%20Module%2C%20but%20I%20can't%20find%20the%20value%20of%20the%20MX%20record%20for%20the%20domain%20anywhere%20in%20the%20Powershell%20module's%20commands.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20tried%20predicting%20the%20MX%20record%20which%20is%20generated%20from%20these%20set%20of%20rules...I%20think....%3C%2FP%3E%3CP%3EExample%3A%3C%2FP%3E%3CP%3EDomain%3A%20contoso.com%3C%2FP%3E%3CP%3ERandom%20String%3A%2001c%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E1.%20Domain%20Name's%20.%20(dot)%20is%20replaced%20by%20-%20(dash)%20resulting%20in%20contoso-com.%3C%2FP%3E%3CP%3E2.%20If%20contoso-com%20unique%20indentifier%20has%20already%20been%20taken%20for%20some%20reason%2C%20add%20some%20random%20string%20in%20the%20end%2C%20so%20the%20MX%20will%20be%20unique.%3C%2FP%3E%3CP%3E3.%20Add%20.mail.protection.outlook.com.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThis%20will%20result%20in%20either%20contoso-com.mail.protection.outlook.com.%20if%20the%20random%20string%20is%20not%20used%2C%3C%2FP%3E%3CP%3Eor%20it%20will%20result%20in%26nbsp%3Bcontoso-com01c.mail.protection.outlook.com.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ESo%20you%20see%20my%20problem%20here.%20I%20cannot%20predict%20the%20MX%20record.%20I%20need%20to%20be%20able%20to%20read%20this%20value%20in%20order%20to%20create%20reliable%20monitors.%3C%2FP%3E%3CP%3EAnd%20I%20can't%20log%20onto%20every%20single%20customer%20and%20write%20down%20each%20and%20every%20MX%20record%2C%20primarily%20because%20I'm%20a%20programmer%2C%20and%20I'm%20a%20programmer%20primarily%20because%20I'm%20lazy.%20There%20I've%20said%20it.%20%3B)%3C%2Fimg%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-205926%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EAdmin%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EExchange%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EHybrid%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EOffice%20365%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-206114%22%20slang%3D%22en-US%22%3ERe%3A%20How%20can%20I%20query%20Exchange%20Online%20for%20the%20generated%20MX%20record%20for%20each%20of%20my%20domains%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-206114%22%20slang%3D%22en-US%22%3E%3CP%3EThat%20was%20exactly%20what%20I%20was%20looking%20for.%20Thank%20you.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-206048%22%20slang%3D%22en-US%22%3ERe%3A%20How%20can%20I%20query%20Exchange%20Online%20for%20the%20generated%20MX%20record%20for%20each%20of%20my%20domains%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-206048%22%20slang%3D%22en-US%22%3E%3CP%3EYes%2C%20it's%20possible%20via%20the%20AzureAD%20module%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EGet-AzureADDomainServiceConfigurationRecord%20-Name%20domain.com%20%7C%20%3F%20%7B%24_.RecordType%20-eq%20%22Mx%22%7D%20%7C%20select%20MailExchange%3C%2FP%3E%3C%2FLINGO-BODY%3E
Highlighted
New Contributor

Is it possible to read the generated MX record for each Email domain in Exchange Online anywhere except on the Admin Portal? For example in Powershell?

More specifically I am talking about the MX record that I'm supposed to set on my domain in order to be able to receive email.

I can see it on the Admin Portal, but I want to be able to query it somehow.

 

The reason for this is that I need to be able to make a monitoring service for the several hundred MX records for my customers' domains.

 

So far, I've been able to list all the domains of all my Tenants with the Powershell MSOnline Module, but I can't find the value of the MX record for the domain anywhere in the Powershell module's commands.

 

I tried predicting the MX record which is generated from these set of rules...I think....

Example:

Domain: contoso.com

Random String: 01c

 

1. Domain Name's . (dot) is replaced by - (dash) resulting in contoso-com.

2. If contoso-com unique indentifier has already been taken for some reason, add some random string in the end, so the MX will be unique.

3. Add .mail.protection.outlook.com.

 

This will result in either contoso-com.mail.protection.outlook.com. if the random string is not used,

or it will result in contoso-com01c.mail.protection.outlook.com.

 

So you see my problem here. I cannot predict the MX record. I need to be able to read this value in order to create reliable monitors.

And I can't log onto every single customer and write down each and every MX record, primarily because I'm a programmer, and I'm a programmer primarily because I'm lazy. There I've said it. ;)

2 Replies
Highlighted
Solution

Yes, it's possible via the AzureAD module:

 

Get-AzureADDomainServiceConfigurationRecord -Name domain.com | ? {$_.RecordType -eq "Mx"} | select MailExchange

Highlighted

That was exactly what I was looking for. Thank you.