Troubleshooting Exchange Online modules connectivity issues

At work I am dealing with this really $hitty Microsoft support team – it’s so frustrating!

For over a month most of my Exchange Online runbooks are intermittently failing with timeouts or similar errors, and I am pretty sure it’s to do with throttling.

The errors vary between cmdlets, but is always consistent. For cmdlets to do with getting distribution group members I get a different error to the above – something about contacting Microsoft support.

So I raise a ticket with Microsoft and they ask you to do the most basic of stuff – put all the cmdlets you are running in a text file along with errors (even though you have sent them screenshots of the errors), and do Fiddler captures of the cmdlets so they can see what’s happening. I don’t think Fiddler is going to help, but they refuse to check their end of the logs until I send all this. Honestly, you pay Microsoft for an E5 license and have all your eggs in their basket, and now you got to run around collecting useless logs just coz their support teams can’t be bothered to do a decent job.

Anyhoo, I collect the logs and send over to them couple of weeks ago; and today they come back saying the logs don’t show any Get-ExoMailbox traffic (that’s the example cmdlet I ran) so I must be doing something wrong. That really ticked me off! Not only are they not listening to what I am saying about where the issue might be, turns out they don’t even know how the new Exchange Online PowerShell cmdlets work. Aargh!

Here’s the Fiddler output.

And here’s the cmdlets I am running:

You can very easily see what’s happening in the Fiddler logs compared to each of these.

When I try to connect it first does a GET request to https://login.microsoftonline.com/common/discovery/instance?api-version=1.1&authorization_endpoint=https%3A%2F%2Flogin.microsoftonline.com%2F<tenant>.onmicrosoft.com%2Foauth2%2Fv2.0%2Fauthorize. The result of that is the following JSON:

Based on this it does a POST to https://login.microsoftonline.com/<tenant>.onmicrosoft.com/oauth2/v2.0/token to get an authorization token. The result is:

That bearer token looks like this:

Using this it then does a GET against https://outlook.office365.com/AdminApi/v1.0/<tenantId>/EXOBanner('AutogenSession')?Version=3.4.0. This is obviously the banner message. We can replicate that manually, using the bearer token:

The result:

Boom!

What happens next is interesting. There’s a GET request to https://outlook.office365.com/AdminApi/v1.0/<tenantId>/EXOModuleFile?Version=3.4.0. What the heck is that?

If I query that manually, I get:

If I dig into the value, it’s actually a bunch of module files!

There’s a lot of cmdlets! I could be mistaken, but it sounds like the installed ExchangeOnlineManagement module is more like a stub module and the first time it connects it goes ahead and downloads a refreshed version of the modules?!

Does it download the latest update to whatever version is installed (i.e. if ExchangeOnlineManagement version 3.2.0 is installed it downloads the latest revisions to that? or does it download the latest available version always – 3.4.0 as of writing? I don’t know and I didn’t test).

Am not sure why it does this weird behaviour though.

Once it gets the modules it also downloads a help file from https://outlook.office365.com/AdminApi/v1.0/<tenantId>/EXOHelpFile?Version=3.4.0. And then we get to the real meat of the business – which in this case, since I am running Get-EXOMailbox results in a GET request to https://outlook.office365.com/adminapi/beta/<tenantId>/Mailbox.

This doesn’t succeed – if I look at the Statistics tab I can seen it gets no reponse:

And this the request is repeated a few times (6 times in my case) and eventually it hits some internal timeout or counter of the module I suppose and we are left with the error I get: Get-EXOMailbox: An error occurred while processing this request.

So, dear Microsoft person, you/ the teams you are escalating to have no real idea of how the ExchangeOnlineManagement module works because clearly you are unable to work out what it’s doing based on the Fiddler logs! (I told them so of course, in no uncertain terms, but not in the level of detail of this blog post).

What is interesting though, as an aside, is that the underlying REST API endpoint is actually a beta! Notice /adminapi/beta/<tenantId>/Mailbox. Wtf!? So while the ExchangeOnlineManagement module is not beta, the endpoints it query are actually beta. Which means what? I guess it means the endpoint URLs can change, the data they return can change… and nothing’s set in stone like a production endpoint.

This must be why the ExchangeOnlineManagement module downloads the latest version/ revision of the modules. Coz that’s how it cheats and can keep up with the ever changing beta endpoint. Sneaky, eh! 😀

Interestingly, there is a v1.0 endpoint too. I can just do:

And it works. (Well, it timed out in my case due to the throttling… but I didn’t get a 404 error or anything!)

As opposed to (I made it v2.0):

Which throws an error:

I Googled on https://outlook.office365.com/AdminApi/v1.0/ and came across this article. Looks like this is the new Outlook Beta REST API, though it seems to use the URL format https://outlook.office.com/api/{version}/{user_context} which is different to what the module cmdlets are using, so I am not sure.

I found some more posts referencing this URL (though nothing helpful) as well as this blog post where someone made a similar discovery to me (albeit, 2 years ago! so we have been in beta for a while).

Anyhoo, not sure what I can do until Microsoft supports gets off their a$$ and sorts out our throttling issue. But it’s good to see the endpoint is in beta as it is really slow and crappy.