Powershell - how to get users that are NOT part of a distribution group
Hello All, I have a distribution list with about 500 of our 1700 employees on it. Is there a way through powershell to get a list of the 1200 or so people NOT on the list? i ran a command to get the users of the distribution list, but need to know who is not on the list. Thank you for any assistance!
January 23rd, 2012 5:10pm

On Mon, 23 Jan 2012 22:04:59 +0000, itzafugasi wrote: > > >Hello All, > >I have a distribution list with about 500 of our 1700 employees on it. Is there a way through powershell to get a list of the 1200 or so people NOT on the list? i ran a command to get the users of the distribution list, but need to know who is not on the list. Something like this will work: $g = 'groupname' $n = @() $m = (get-group $g).members get-recipient | foreach { if ($m -notcontains $_.distinguishedname) { $n += $_ } } $n | select displayname | export-csv c:\temp\notmember.csv -notype --- Rich Matheisen MCSE+I, Exchange MVP --- Rich Matheisen MCSE+I, Exchange MVP
Free Windows Admin Tool Kit Click here and download it now
January 23rd, 2012 10:29pm

Thanks so much. If i wanted to check multiple distribution groups, how can i use an "and" operator? so for example, i want to see what users are NOT part of groupA and groupB and groupC. Thanks again!
January 24th, 2012 10:24am

On Tue, 24 Jan 2012 15:17:58 +0000, itzafugasi wrote: > > >Thanks so much. If i wanted to check multiple distribution groups, how can i use an "and" operator? > >so for example, i want to see what users are NOT part of groupA and groupB and groupC. Do you really mean "AND"? Or are you looking to see which users are not a member of each individual group? If you just want to know who's not a member of each group taken individually it's pretty simple: $groups = 'group1','group2','group3' foreach ($group in $groups) { $n = @() $m = (get-group boing).members get-recipient | foreach { if ($m -notcontains $_.distinguishedname) { $n += $_ } } $n | select displayname | export-csv "c:\temp\notmemberof_$group.csv" -notype } --- Rich Matheisen MCSE+I, Exchange MVP --- Rich Matheisen MCSE+I, Exchange MVP
Free Windows Admin Tool Kit Click here and download it now
January 24th, 2012 11:55am

Thanks again. I'm trying to find out if userA does not belong to groupa, and b, and c. so in other words, there's a list of users that do not belong to 10 distro lists. I'd like to know who those users are.
January 24th, 2012 1:51pm

On Tue, 24 Jan 2012 18:44:44 +0000, itzafugasi wrote: >Thanks again. I'm trying to find out if userA does not belong to groupa, and b, and c. > >so in other words, there's a list of users that do not belong to 10 distro lists. I'd like to know who those users are. Just to be clear, you're interested in a list of users that are not a member of ANY of those ten groups? For example, assume there are four users in the AD, and there are two groups with the following membership: Group1: .. User1 .. User2 Group2: .. User1 .. User3 You'd want to know that User4 is not a member of either Group1 or Group2? If so, that would be a "complement set" (or a "set inverse"). To put your problem a different way, you're looking for an answer similar to the results of "show me all the web pages that don't talk about Exchange", is that correct? --- Rich Matheisen MCSE+I, Exchange MVP --- Rich Matheisen MCSE+I, Exchange MVP
Free Windows Admin Tool Kit Click here and download it now
January 24th, 2012 3:33pm

Exactly...the reason is as follows: Lets say i have 10 distro lists. 1700 users in the org. 1600 are on those lists, but 100 are not. I don't know who those 100 users are. There's a process that runs on the 1600 users mailboxes, and it's not running on the 100 users because they do not belong to any one of those 10 groups. I need to find out who those 100 users are. I hope that makes sense...
January 24th, 2012 3:57pm

Are any of these distribution lists dynamic, or are they all regular distribution lists? If they're all regular it cuts down on the coding required. Cheers, Lain
Free Windows Admin Tool Kit Click here and download it now
January 24th, 2012 7:30pm

On Tue, 24 Jan 2012 20:50:43 +0000, itzafugasi wrote: > > >Exactly...the reason is as follows: > >Lets say i have 10 distro lists. 1700 users in the org. 1600 are on those lists, but 100 are not. I don't know who those 100 users are. There's a process that runs on the 1600 users mailboxes, and it's not running on the 100 users because they do not belong to any one of those 10 groups. I need to find out who those 100 users are. > >I hope that makes sense... Try this: $groups = 'group1','group2','group3' $notpresent = @() $ourset = @{} foreach ($group in $groups) { $members = (get-group $group).members foreach ($member in $members) { if ( !$ourset.contains($member.distinguishedname) ) { $ourset.($member.distinguishedname) = $true } } } get-recipient | foreach { if ( !$ourset.contains($_.distinguishedname) ) { $notpresent += $_ } } $notpresent | select displayname | export-csv "c:\temp\notmemberofanygroup.csv" -notype --- Rich Matheisen MCSE+I, Exchange MVP --- Rich Matheisen MCSE+I, Exchange MVP
January 24th, 2012 11:06pm

On Tue, 24 Jan 2012 20:50:43 +0000, itzafugasi wrote: > > >Exactly...the reason is as follows: > >Lets say i have 10 distro lists. 1700 users in the org. 1600 are on those lists, but 100 are not. I don't know who those 100 users are. There's a process that runs on the 1600 users mailboxes, and it's not running on the 100 users because they do not belong to any one of those 10 groups. I need to find out who those 100 users are. > >I hope that makes sense... Try this: $groups = 'group1','group2','group3' $notpresent = @() $ourset = @{} foreach ($group in $groups) { $members = (get-group $group).members foreach ($member in $members) { if ( !$ourset.contains($member.distinguishedname) ) { $ourset.($member.distinguishedname) = $true } } } get-recipient | foreach { if ( !$ourset.contains($_.distinguishedname) ) { $notpresent += $_ } } $notpresent | select displayname | export-csv "c:\temp\notmemberofanygroup.csv" -notype --- Rich Matheisen MCSE+I, Exchange MVP --- Rich Matheisen MCSE+I, Exchange MVP
Free Windows Admin Tool Kit Click here and download it now
January 25th, 2012 7:00am

all lists are regular - thanks rich, i'm going to give it a shot now. update - exactly what i needed, thanks so much Rich!
January 25th, 2012 10:59am

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

Other recent topics Other recent topics