Hi Everyone
I have been struggling with this query for a year. While I feel it should be so simple.
Need a dynamic all staff group.
Using the 'all exchange mailboxes' option; includes shared mailboxes, distribution groups, and contacts which I do not want.
Tried in azure, linking it to license codes, but hit too many dead ends.
Powershell is the way...
Found a promising route and as I was playing around with it, I found out it filtered nothing.
Here is what I need:
• Dynamic distribution group with all users in
• Exclude sharedmailboxes, distribution, security, contacts etc.
• Exclude admin accounts sysadmin@***
Here is what I have:
New-DynamicDistributionGroup -Name "o" -RecipientFilter {(`
>> (RecipientType -eq 'UserMailbox') `
>> -and (-not(RecipientType -eq 'MailContact')) `
>> -and (-not(MemberOfGroup -eq 'CN=AllExclusion,OU=SG,DC=Example,DC=Local')) `
>> -and (-not(Name -like 'Sysadmin{*')) `
>> -and (-not(Name -like 'CAS_{*')) `
>> -and (-not(RecipientTypeDetailsValue -eq 'MailboxPlan')) `
>> -and (-not(RecipientTypeDetailsValue -eq 'DiscoveryMailbox')) `
>> -and (-not(RecipientTypeDetailsValue -eq 'PublicFolderMailbox')) `
>> -and (-not(RecipientTypeDetailsValue -eq 'ArbitrationMailbox')) `
>> -and (-not(RecipientTypeDetailsValue -eq 'AuditLogMailbox')) `
>> -and (-not(RecipientTypeDetailsValue -eq 'AuxAuditLogMailbox')) `
>> -and (-not(RecipientTypeDetailsValue -eq 'SupervisoryReviewPolicyMailbox')) `
>> -and (-not(RecipientTypeDetailsValue -eq 'GuestMailUser'))`
>> )}
Drilled down and found no difference in users, using any of these codes:
o1 - New-DynamicDistributionGroup -Name "o" -RecipientFilter {(RecipientType -eq 'UserMailbox') -and (-not(DisplayName -like 'Archive{*'))}
o2 - New-DynamicDistributionGroup -Name "o" -RecipientFilter {(RecipientType -eq 'UserMailbox')}
o3 - New-DynamicDistributionGroup -Name "o" -RecipientFilter {(RecipientType -eq 'UserMailbox')-and (-not(Name -like 'Archive{*'))}
This is how I get the results
Get-Recipient -RecipientPreviewFilter (Get-DynamicDistributionGroup -Identity "o").RecipientFilter -Resultsize unlimited | Export-csv C:\o.csv
Please help. I feel pathetic, that such a straight forward request, is so complex and has taken so long.