Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save JustinGrote/0dedc42692be19432f8aa3b8f8151710 to your computer and use it in GitHub Desktop.

Select an option

Save JustinGrote/0dedc42692be19432f8aa3b8f8151710 to your computer and use it in GitHub Desktop.
Exchange: Get a list of Distribution Groups
#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