Solved

List active users in Dynamic Distrubution list

Posted on 2013-06-03
9
436 Views
Last Modified: 2013-06-04
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!
0
Comment
Question by:Mr Woober
9 Comments
 
LVL 22

Expert Comment

by:Haresh Nikumbh
ID: 39216383
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
0
 
LVL 26

Accepted Solution

by:
Leon Fester earned 500 total points
ID: 39217537
You can use the get-mailbox cmdlet on Exchange Server.
Filters can be applied using the useraccountcontrol variable.

You can try the command:
Get-Mailbox |?{$_.UserAccountControl -Match "normalAccount"}| Fl Name,Database,UserAccountControl

It's a modified query based on:
http://forums.msexchange.org/how_to_use_Exchange_Management_Shell_to_find_disabled_AD_users_with_mailboxes/m_1800563621/tm.htm
AND
http://blogs.bamits.com.au/2011_07_01_archive.html
0
 
LVL 4

Expert Comment

by:Satish Auti
ID: 39218103
Try attached script.....
Gropus.vbs
0
 
LVL 1

Author Comment

by:Mr Woober
ID: 39218239
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.
0
 
LVL 26

Assisted Solution

by:Leon Fester
Leon Fester earned 500 total points
ID: 39218288
erm... if you are using Dynamic groups, then configure your query to exclude disabled accounts.

FYI The query to create the Dynamic groups is run each time that your use the Dynamic groups....so if you exclude disabled accounts in the query you'll never need to maintain the list.

See links below:
http://www.experts-exchange.com/Software/Server_Software/Email_Servers/Exchange/Q_23987324.html#a23186983
http://social.technet.microsoft.com/Forums/en-US/winserverpowershell/thread/00aeef18-6528-42a0-9760-118479bf9a7c
http://www.experts-exchange.com/Software/Server_Software/Email_Servers/Exchange/Q_25206374.html#a26856470
0
 
LVL 1

Author Comment

by:Mr Woober
ID: 39218338
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 :)
0
 
LVL 1

Author Closing Comment

by:Mr Woober
ID: 39218339
Thanks :)
0
 
LVL 26

Expert Comment

by:Leon Fester
ID: 39218341
OOOO  "C:\lager" what kind of breweries do you work for?
0
 
LVL 1

Author Comment

by:Mr Woober
ID: 39218515
Its norwegian :)
0

Join & Write a Comment

Synchronize a new Active Directory domain with an existing Office 365 tenant
Following basic email etiquette rules will help you write a professional email and achieve a good, lasting impression with your contacts.
This tutorial will walk an individual through the steps necessary to install and configure the Windows Server Backup Utility. Directly connect an external storage device such as a USB drive, or CD\DVD burner: If the device is a USB drive, ensure i…
This video discusses moving either the default database or any database to a new volume.

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now