Link to home
Start Free TrialLog in
Avatar of Mr Woober
Mr WooberFlag for Norway

asked on

List active users in Dynamic Distrubution list

I'm trying to get out a list over all active users that has an active account with mailbox on Exchange 2010. I managed to get a full list, but its over 100 users, so I would like to narrow down the list, to only output those active accounts with an mailbox.

I tried different scripts with Get-DistributionGroupMember and Get-DynamicDistributionGroup, but they only list all users, also those disabled.

Thanks in advance for any help!
Avatar of Haresh Nikumbh
Haresh Nikumbh
Flag of India image

To remove disabled Active Directory user accounts from all distribution groups in the organization, use the following code:


$groups = Get-DistributionGroup -ResultSize Unlimited

$report = foreach($group in $groups){
 Get-DistributionGroupMember $group |
  ?{$_.RecipientType -like '*User*' -and $_.ResourceType -eq $null} |
   Get-User | ?{$_.UserAccountControl -match 'AccountDisabled'} |
    Select-Object Name,RecipientType,@{n='Group';e={$group}}
}

$report | Export-CSV c:\disabled_group_members.csv -NoType



http://www.packtpub.com/article/exchange-server-2010-windows-powershell-distribution-groups
ASKER CERTIFIED SOLUTION
Avatar of Leon Fester
Leon Fester
Flag of South Africa image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Try attached script.....
Gropus.vbs
Avatar of Mr Woober

ASKER

Thanks for the tips, this group is a dynamic group. So I probably need to remove the disabled accounts, does it remove the mailbox aswell? Because I might need to reactivate the user later.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I manage to solve it :)

Here is what I did:

$list = read-host "Name on group"

Set-DynamicDistributionGroup -Identity "$list" -RecipientFilter {
  (EmailAddresses -like '*hero*') -and
  (HiddenFromAddressListsEnabled -ne $true)
}

$MarketingGroup = Get-DynamicDistributionGroup "$list"
Get-Recipient -RecipientPreviewFilter $MarketingGroup.RecipientFilter -OrganizationalUnit $MarketingGroup.OrganizationalUnit -SortBy Name >> C:\lager\activeusers.txt

Thanks for the help :)
Thanks :)
OOOO  "C:\lager" what kind of breweries do you work for?
Its norwegian :)