list of all distribution lists that one user is a member of. Powershell?
I have to get a list of all distribution lists that one user is a member of. Can this be done via powershell?
August 16th, 2012 5:00am

Yes, you can use powershell to accomplish this. $Groups=@() $User = get-mailbox <UserIdentity>; Get-DistributionGroup | foreach { $dg = $_.Name Get-DistributionGroupMember $dg | foreach {if ($_.identity -eq $User.identity) {$Groups += $DG} } } $Groups
Free Windows Admin Tool Kit Click here and download it now
August 16th, 2012 5:18am

Hi Rajitha Thanks for the swift reply, I've tried the script but it asks for the following cmdlet Get-DistributionGroupMember at command pipeline position 1 Supply values for the following parameters: Identity: I have tried alias, display name and email address all give same result as above. Where am I going wrong? Thanks in advance
August 16th, 2012 6:14am

Sorry, my fault. Please try this. $Groups=@() $User = get-mailbox <UserIdentity>; Get-DistributionGroup | foreach { $dg = $_.Name Get-DistributionGroupMember $dg | foreach {if ($_.identity -eq $User.identity) {$Groups += $DG} } } $Groups
Free Windows Admin Tool Kit Click here and download it now
August 16th, 2012 6:47am

I'm still getting this wrong. I'm substituting <UserIdentity> with the users alias and executing. Should this give me all the DLs that the user is a member of? It only comes up with 2 DLs but when I check AD, the user is a member of 9 lists Pipeline not executed because a pipeline is already executing. Pipelines cannot be executed concurrently. + CategoryInfo : OperationStopped: (Microsoft.Power...tHelperRuns pace:ExecutionCmdletHelperRunspace) [], PSInvalidOperationException + FullyQualifiedErrorId : RemotePipelineExecutionFailed WARNING: By default, only the first 1000 items are returned. Use the ResultSize parameter to specify the number of items returned. To return all items, specify "-ResultSize Unlimited". Be aware that, depending on the actual number of items, returning all items can take a long time and consume a large amount of memory. Also, we don't recommend storing the results in a variable. Instead, pipe the results to another task or script to perform batch changes. 1st DL 2nd DL PS> Where would I insert the "-ResultSize Unlimited" line?
August 16th, 2012 7:14am

$Groups=@() $User = get-mailbox <UserIdentity>; Get-DistributionGroup -Resultsize unlimited | foreach { $dg = $_.Name Get-DistributionGroupMember $dg | foreach {if ($_.identity -eq $User.identity) {$Groups += $DG} } } $Groups You can also add -Resultsize unlimited against Get-Distributiongroupmember cmdlet if you still see this error again.
Free Windows Admin Tool Kit Click here and download it now
August 16th, 2012 7:16am

Hello, I don't think powerhsell Script is a good option, because there will two loop in the script, when you have too many distribution groups, this may effect Exchange Server performance. If you want to know user is member of which groups, you can go to check on ADUC: user properties->member of If you want to use powershell commands, here is one script for you: $User = read-host -Prompt "Enter User" $User + " is a member of these groups:" ForEach ($Group in Get-DistributionGroup) { ForEach ($Member in Get-DistributionGroupMember -identity $Group | Where { $_.Name eq $User }) { $Group.name } } Thanks, EvanEvan Liu TechNet Community Support
August 17th, 2012 5:33am

Hello, I don't think powerhsell Script is a good option, because there will two loop in the script, when you have too many distribution groups, this may effect Exchange Server performance. If you want to know user is member of which groups, you can go to check on ADUC: user properties->member of If you want to use powershell commands, here is one script for you: $User = read-host -Prompt "Enter User" $User + " is a member of these groups:" ForEach ($Group in Get-DistributionGroup) { ForEach ($Member in Get-DistributionGroupMember -identity $Group | Where { $_.Name eq $User }) { $Group.name } } Thanks, EvanEvan Liu TechNet Community Support
Free Windows Admin Tool Kit Click here and download it now
August 17th, 2012 5:35am

RedMick, Also remember, you asked about Distribution Lists and everyone assumed you were talking about Exchange DLs, but yet you mention looking at groups in ADUC. All groups listed in ADUC may not be Distribution Lists for Exchange. If you want to see all Group Membership of a user, try this: If (!(Get-module -name activedirectory)) { Import-Module ActiveDirectory } $User = read-host -Prompt "Enter User" $Groups = $(Get-ADUser $User -Properties memberOf).memberOf Foreach ($Group in $Groups) { Get-ADGroup $Group | FT }
August 17th, 2012 10:32am

RedMick, Also remember, you asked about Distribution Lists and everyone assumed you were talking about Exchange DLs, but yet you mention looking at groups in ADUC. All groups listed in ADUC may not be Distribution Lists for Exchange. If you want to see all Group Membership of a user, try this: If (!(Get-module -name activedirectory)) { Import-Module ActiveDirectory } $User = read-host -Prompt "Enter User" $Groups = $(Get-ADUser $User -Properties memberOf).memberOf Foreach ($Group in $Groups) { Get-ADGroup $Group | FT }
Free Windows Admin Tool Kit Click here and download it now
August 17th, 2012 10:33am

another possibility: Get-ADUser $user | Get-ADPrincipalGroupMembership | select -Expand Distinguishedname | Get-DistributionGroup -EA 0 [string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "
August 17th, 2012 11:01am

another possibility: Get-ADUser $user | Get-ADPrincipalGroupMembership | select -Expand Distinguishedname | Get-DistributionGroup -EA 0 [string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "
Free Windows Admin Tool Kit Click here and download it now
August 17th, 2012 11:03am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics