Scripts and functions for M365 with dynamic parameters: Impossible? No!

Recently I wanted to updated an old function, which I use in my daily work for Privilege Identity Management. Initially I just wanted to move over from using AzureADPreview to Microsoft Graph PowerShell SDK, but sometimes you just do more.

However, this was a good learning curve for me and I thought sharing would be helpful.

Continue reading

Format MessageTraceDetail in Exchange Online

Over the last weeks, I had to perform more than usual message traces in Exchange Online. For more details how to run such traces, Tony recently updated his article:

Exchange Online Message Traces are Different to On-Premises Searches (

However, the details you want to look at are not really formatted in a readable format.

Continue reading

Maintain MAPI permissions recursive

I strongly believe that many of you already run into this scenario:

“Hey, can you help me and grant access to all my folders in my mailbox to this one person?”

When it starts like this, in most cases this user has folders, where the total number is for sure more than 2 digits.

Continue reading

Microsoft Graph: Get group info

As mentioned in my previous post here, daily tasks shifted and so I had a closer look into Microsoft Graph. In this post it’s about retrieving group information.


In my daily work, I often have to deal with topics, where I need to collect more information about a group. Yes, the new UI in the AAD portal helps, but doesn’t provide all the information. On the other side there are a ton of PowerShell modules e.g.: MSOL, AzureAD or AzureADPreview.

Sorry, but I’m unhappy as not one module, gives me all information. In fact in some cases I have to use MSOL and AzureADPreview in order to get the whole picture. Besides the fact that some Cmdlets just throw an error in larger environements.


The only solution for me was to use Microsoft Graph and therefore, I wrote a function called Get-MSGraphGroup. Same like my other function Get-MSGraphUser, it incorporates all techniques from Microsoft Graph:

The function has the following parameters:

    This function uses Microsoft Office application for retrieving access token and queries Microsoft Graph for group properties.
    The Microsoft Office with ClientID d3590ed6-52b3-4102-aeff-aad2292ab01c can be used to retrieve an access token with the scopes AuditLog.Read.All, Calendar.ReadWrite, Calendars.Read.Shared, Calendars.ReadWrite, Contacts.ReadWrite, DeviceManagementConfiguration.Read.All, DeviceManagementConfiguration.ReadWrite.All, Directory.AccessAsUser.All, Directory.Read.All, email, Files.Read, Files.Read.All, Group.Read.All, Group.ReadWrite.All, Mail.ReadWrite, openid, People.Read, People.Read.All, profile, User.Read.All, User.ReadWrite, Users.Read
    The parameter Group defines the id of the group. Unless you use the parameter ByMail. If this parameter is used in addition, the function tries to get the id of the group by searching for a group with the specified e-mail address.
.PARAMETER AccessToken
    This optional parameter AccessToken can be used if you want to use your own application with delegated or application permission. The parameter takes a previously acquired access token.
    The parameter ByMail is a switch, which can be used in combination with Group, when an e-mail address instead of an id is used.
    The parameter Filter can be used, when you want to use a complex filter.
.PARAMETER ShowProgress
    The parameter ShowProgress will show the progress of the script.
.PARAMETER ReturnMembers
    Switch to return members of group.
.PARAMETER ReturnMembersTransitive
    Switch to return transitive members of group.
    The parameter Threads defines how many Threads will be created. Only used in combination with MultiThread.
.PARAMETER MultiThread
    The parameters MultiThread defines whether the script is running using multithreading.
.PARAMETER Authority
    The authority from where you get the token.
    Application ID of the registered app.
.PARAMETER ClientSecret
    The secret, which is used for Client Credentials flow.
.PARAMETER Certificate
    The certificate, which is used for Client Credentials flow.
    How many retries for each user in case of error.
    TimeoutSec for Cmdlet Invoke-RestMethod.
.PARAMETER MaxFilterResult
    MaxFilterResult when Filter is used.
    Get-MSGraphGroup -Group -ByMail
    Get-MSGraphGroup -Group 6288514a-9840-4426-as05-d2955a03ea27
    Get-MSGraphGroup -Filter Get-MSGraphGroup -Filter "startswith(mail,'ServicesSale')"
    If you want to use your own application make sure you have all the necessary minimum permission assigned: Group.Read.All (this might change in the future. Consult the full permission reference for Microsoft Graph)

It has basically same functionality like Get-MSGraphUser, with the difference that it retrieves data from groups.


The function also supports multi threading using PowerShell runspaces. On top of this it is important to understand the following parameters:

  • ReturnMembers
  • ReturnMembersTransitive

By default only the total number of members will be returned. IF you need to get all members, you can use one of those switches. Be aware that this can take a while and depends on how many members a group has.

You might wonder about the difference between both:

ReturnMembers will return only members of a group. This can also be another group. It will not recursively resolve all levels down to a user object.

ReturnMembersTransitive will exactly do this for you: recursively retrieve flat list of all users.


Just to give you a real-life example. We receive very often tickets, where it is asked about checking Exchange for issues as it seems not all members of a group received an important e-mail.

Well, before it was some kind of hassle to get the flat list of users. Now with this it’s easy as you can just use Microsoft Graph and transitiveMembers.

Where can I get the code?

As mentioned in previous posts, I’m super lazy and that’s why I have it somehow automated to load all my little helpers in combination with a tweaked PowerShell profile. You can find my little helpers here:

You might wonder about the needed application and permissions. No worries as you can use (partially) the app “Microsoft Office” (appId: d3590ed6-52b3-4102-aeff-aad2292ab01c), which is available to everyone and has even the scope Group.Read.All or Directory.Read.All. Usually these permissions require Global Admin consent!


I hope this code helps YOU in your daily work. Feedback is always welcome!

Update delegate collection challenge

A few days ago, I was approached by some Executive Support colleagues. The had to handle a lot of mail items in shared mailboxes. One issue the came across, was the fact that they had to move items and delete folders, but couldn’t as the folders contained private items.

Note: Don’t get me started about the use case “Private Items”! It doesn’t gives you any security value as it’s only honored by a few clients!

Well, back to the topic…I’m aware of this behavior and there is also a KB article about this topic:

“Cannot copy this folder because it may contain private items” error in Outlook

Since the shared mailbox is in M365 and the fasted way with least effort was to add the permissions for this user using Add-MailboxFolderPermission and make use of parameter -SharingPermissionFlags.

That’s what I thought and then run into this…

Continue reading

Microsoft Graph: Get user info

Over the last weeks I had a steep learning curve with Microsoft Graph. In my daily job and especially as we moved to M365 it’s absolutely necessary querying attributes for users.

On-premises you most likely would use Get-AdUser or even just ADSI to do so. With the move to M365 you will call Microsoft Graph. And of course make use of OAuth2.0 flows for authentication and authorization.

Continue reading

The future of Exchange Online automation with EXOv2

I know that this topic is really a topic with gets high attention.At the moment there is nothing available in Microsoft Graph, which would make it possible to manage objects in Exchange Online.

The few things, which exists, are more for end-user (e.g.: accessing their e-mails, calendar or tasks) and for auditing and reporting (e.g.: Security API). Nothing available for managing a mailbox permissions or attributes. Not even like simple CustomAttribute1-15.

Now Microsoft released a new Exchange Online PowerShell module: EXOv2.

Continue reading

EXO V2 module, earlier .NET versions and pesky TLS1.0/1.1

It’s been a while that the new module for managing Exchange Online using PowerShell.If not yet aware, please check out how to Use the Exchange Online PowerShell V2 module.

It’s not perfect (yet!), but huge improvements and Microsoft is working hard to get the module improved.

On my transition to the new module, I was made aware of connectivity issues by some colleagues:

New-ExoPSSession : An error occurred while sending the request..
At C:\Program Files\WindowsPowerShell\Modules\ExchangeOnlineManagement\0.3582.0\ExchangeOnlineManagement.psm1:401 char:30…

PSSession = New-ExoPSSession -ExchangeEnvironmentName $ExchangeEnviro …

But the issue existed ONLY when using the parameter -Credential

Continue reading