Forum Discussion
Sam240
Apr 01, 2022Copper Contributor
Users not part of office distribution lists PowerShell
I'm looking to find office365 users whose primary SMTP is our domain.com that are not part of certain office365 distribution lists we have. For example Dist1, Dist2, Dist3, Dist4 and export the resul...
Newbie_Jones
Brass Contributor
Why the two client side filters in the Get-Mailbox line? Performance wise that looks strange.
Can't we use a server side filter on Get-Mailbox for the two PrimarySmtpAddress elements?
Can't we use a server side filter on Get-Mailbox for the two PrimarySmtpAddress elements?
May 16, 2022
You can use whatever filter you want 😉 I added the discoverymailbox because it was also evaluated, you can leave that out if you want.. Performance wise there was no impact in my test environment, very few users, but in larger environments it could take somewhat longer. But is this something you run once in a while or daily?
Shorter version:
Get-Mailbox | Where-Object {$_.PrimarySmtpAddress -Match 'M365x537152.OnMicrosoft.com' -and $_.PrimarySmtpAddress -NotMatch 'DiscoverySearchMailbox'} | Sort-Object UserPrincipalName
- Newbie_JonesMay 17, 2022Brass Contributor
Can't this all be done server side.
Get-Mailbox -Filter {$_.PrimarySmtpAddress -Match 'M365x537152.OnMicrosoft.com' -and $_.PrimarySmtpAddress -NotMatch 'DiscoverySearchMailbox'} | Sort-Object UserPrincipalName
- May 17, 2022Not sure what you mean with server side? You connect Exchange Online and run the commands directory on that...
- Newbie_JonesMay 17, 2022Brass ContributorIn your example, you are piping the Get-Mailbox account into Where-Object. This means it has to get all of the mailboxes first and then filter client side. The processing of this is done on the machine running the shell. (Client side).
If you use the -Filter on the Get-Mailbox command, this is then processed server side. Usually improving the performance of the script, particularly if there is a lot of data to filter which there would be in this case as you are looking at all mailboxes.
https://techcommunity.microsoft.com/t5/skype-for-business-blog/filter-vs-where-object/ba-p/618442
https://sid-500.com/2017/06/24/powershell-filtering-objects-vs-where-object/