Saturday, January 25, 2020

Putting Exchange Online PowerShell V2 to Work

So, they say it's faster. And more reliable. Had to run few tests with the most common queries.

Getting single mailboxes

When requesting single mailboxes, difference is already notable. When using old Get-Mailbox it took around 450ms (from Finland where I'm performing my tests, over quite bad ADSL line, thanks to my ISP). New Get-EXOMailbox cmdlet returned lightweight mailbox objects around 200ms.


Get-EXOMailbox -Identity pete@phelme.onmicrosoft.com


Old: ~450ms
New: ~200ms

When testing single mailboxes, I was running 2 parallel powershell sessions, old cmdlets with c2r-MFA-capable-EXOService-module and other with new V2 ExchangeOnlineManagement. Note that legacy Get-Mailbox cmdlet in the V2 module is as slow as it is in the old one.

There's major difference in returned payload. With the EXO V2 you only get the minimum set of properties:

More mailboxes

Next bit more challenging query. Show me all your UserMailboxes (out of approx. 22k boxes).

$mailboxes = Get-EXOMailbox -RecipientTypeDetails UserMailbox -ResultSize Unlimited


Old: 350675ms (5 min, 50 sec)
New: 115325ms (1 min, 55 sec)

It IS faster. Both returned same set of items, just under 18k mailboxes.

Mailbox Statistics

How about the most expensive one, mailbox statistics. Let's get statistics for first 1000 mailboxes.

$stats = $mailboxes | Select -f 1000 | Get-EXOMailboxStatistics -ErrorAction Continue


Old: 480486ms (8 min)
New: 477638ms (7 min, 57 sec)

No notable improvement there. Of course you'll be saving memory, only most used properties are passed by default when using new EXO V2 module:

Mobile Device Statistics

When running statistics for mobile devices I realized that new V2 module is not surfacing errors even if I define -ErrorAction "Continue" in the cmdlet. It just goes on as if all's good. Actually Get-EXOMobileDeviceStatistics doesn't raise errors at all for missing statistics. Might be by design though.

The old one is writing out errors as expected:

And how about the speed? A bit faster, saves you 20%.


$mobilestats = $mailboxes | Select -f 1000 | Get-EXOMobileDeviceStatistics


Old: 7 minutes
New: 5 min 19 sec

Mobile stats in module V2 gives larger set by default:

Session lifetime

I was surprised that module V2 renewed session automatically when old module just prompted for new credentials.


So, based on first runs it's good, it's faster. It's lighter. Reliability remains to be seen. When testing cmdlets in your own tenant you might experience totally different performance for better or for worse.

Keep on scripting, see you!

Wednesday, January 22, 2020

Finally, Exchange Online PowerShell module available in PS Gallery

As you should know already, Microsoft is axing Exchange Online legacy authentication this year (Oct 13th 2020 to be exact). Still many of automations are relying on basic authentication, which is bad.

Edit: Microsoft postponed deprecation of Exchange Online basic authentication due to COVID-19 situation. New estimated deadline is around Q2/2021.

Before there was this odd click-2-run package of modern authentication capable EXO module. I never quite got why they did it that way but I'm glad we can soon forget it completely. You can now install new Exchange Online PowerShell V2 module from the PS Gallery as it always should've been. Note that it was still in preview when writing this post.

There's really good documentation on the new module (the previous link), but let me save you a click and introduce it here briefly.

How to install

Note: All install cmdlets must be run with elevated PowerShell session (as administrator).

Install-Module -Name ExchangeOnlineManagement


You might get an error: WARNING: The specified module ... with PowerShellGetFormatVersion ‘2.0’ is not supported by
the current version of PowerShellGet. Get the latest version of the PowerShellGet module to install this module ...


If error occurs, you have to update PowerShellGet.


Install-PackageProvider -Name NuGet -Force
Exit

Install-Module -Name PowerShellGet -Force
Exit

Update-Module -Name PowerShellGet
Exit



How to use


Import-Module ExchangeOnlineManagement
$cred = Get-Credential

Connect-ExchangeOnline -Credential $cred

So, you can basically use stored credentials in your scripts and connection is made using "Modern Authentication". Azure AD sees actor as "Mobile Apps and Desktop clients" type of rich client. Actually, new EXO PS module cannot be used with basic auth at all.



Whats new?

EXO V2 module also has a few new cmdlets, prefixed with "EXO". Old versions of these cmdlets are still there for backward compatibility.

Get-Command -Module ExchangeOnlineManagement -Noun "EXO*"

New cmdlets revealed:

Get-EXOCasMailbox
Get-EXOMailbox
Get-EXOMailboxFolderPermission
Get-EXOMailboxFolderStatistics
Get-EXOMailboxPermission
Get-EXOMailboxStatistics
Get-EXOMobileDeviceStatistics
Get-EXORecipient
Get-EXORecipientPermission

New cmdlets should be more robust and therefore new V2 module introduces "property sets". You can request only properties that are relevant to your specific use case. Check available sets here.

Happy scripting and start planning modern authentication for all your scripts now!

Saturday, January 18, 2020

Intro


The beginning

This isn't really the first blog I've written but is definitely the 1st published here in my own tech(ish) blog. So, let me introduce myself shortly.

I'm Pete, living in Finland in a city called Järvenpää (Jar-when-bad?). Yes, it's quite unpronounceable place to live, but you can also say "near Helsinki". I've worked in IT (or ICT) my whole career and started my first real job during the great WinNT era. We were programming with C, VB and with ancient tools no one remembers any more (Plexus, LightSpeed, SCO Unix, Informix databases). But we did do kind of cool stuff back in late 90's, like image archiving with WORM jukeboxes, optical character recognition (OCR), in-house case and document management solutions. And all without the helping hands of Google and Stack Overflow. Ok, we did have AltaVista.

During the years I've done my share of SharePoint "tailoring". And made few intranets with SharePoint Online also. I've worked with Office 365 since the launch of the service (still remember the summer of 2011). Not long after O365 was launched, I was hired as a consultant to Sulava Oy. Still there and happy!

Oh, and I have a life/family too. I'm living with my lovely wife and soon-to-be adult son, we have two not-so-bright belgian shepherds (that is a brand of a dog), a small house with a garden and a sports utility vehicle (or we did have, now waiting for the next one to be assembled somewhere in Mexico).

About the blog

For a while I wondered if I should write in Finnish or in English. My Swedish is so "dåligt" I couldn't consider that one. So, I decided to go with English. Most of the referenced articles are anyway in English and computing just won't translate to Finnish very well. So I'll do with my not-so-native English. Please do ask/comment if you can't make sense of my posts.

Initially I planned this to be a PowerShell blog related to Microsoft 365. But I think I'll reserve a right to change my mind if something interesting should appear. Maybe write a few words about Log Analytics. Or adventures in AIP or DLP. I hope that I can bring something extra to the table. At least I've seen a lot with my wonderful customers and I think there's few experiences to be shared with you all.

I don't do fb or ig but (re)tweeting as @helipetr.

That's all for now, see you! Oh wait, you can already read the 1st post with substance in it, about EXO PowerShell V2.