Created
August 3, 2026 22:59
-
-
Save JustinGrote/0dedc42692be19432f8aa3b8f8151710 to your computer and use it in GitHub Desktop.
Exchange: Get a list of Distribution Groups
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #This exploits the fact that you can have up to 500 filter parameters to a get-distributiongroup query (but I do 450 here to be conservative) | |
| #This is much faster than trying to do it via runspaces. | |
| function Get-DistributionGroupBatch { | |
| param( | |
| [string[]]$Name, | |
| [int]$BatchSize = 450 | |
| ) | |
| for ($i, $i -lt $Name.Count; $i += $BatchSize) { | |
| $batch = $Name[$i..([Math]::Min($i + $BatchSize - 1, $Name.Count - 1))] | |
| $filter = ($batch | ForEach-Object { "Name -eq '$_'" }) -join ' -or ' | |
| Get-DistributionGroup -Filter $filter | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment