Avatar of quickslvr
quickslvr
Flag for Switzerland asked on

Content CheckUp for Distribution List

Hi all,

I need to verify how and if our DL`s are used. Is there a command how to verify if DL`s are empty and unused?

we have exchange 2007 sp1.
Exchange

Avatar of undefined
Last Comment
quickslvr

8/22/2022 - Mon
Hendrik Wiese

Please try the following and let me know if it works:

Get-MessageTrackingLog -EventID Expand | Group RelatedRecipientAddress | ft count, name
quickslvr

ASKER
something is not quite ok,there are tons of error messages.

i just need to know about our Distribution Lists if and how the`re used, not more
Hendrik Wiese

Try the following:
Get-DistributionGroup -resultsize unlimited | ft name, count
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
quickslvr

ASKER
its the same thing as before.

I just need to know if any of our DL`s has any kind of content, i.e. do those DL`s contain any user objects/mail adresses or not
Hendrik Wiese

o ok,

In that case try the following:
get-distributiongroup -resultsize unlimited | where { `$_.AcceptMessagesOnlyFrom.count -eq "0" `
-and $_.AcceptMessagesOnlyFromDLMembers.count -eq "0" `
-and $_.RequireSenderAuthenticationEnabled -eq $false `
-and $_.RejectMessagesFrom.count -eq "0" `
-and $_.RejectMessagesFromDLMembers.count -eq "0" `
}

Ref: http://social.technet.microsoft.com/Forums/en-US/exchangesvradmin/thread/f6e22be1-7ecd-4349-9974-aeae3f1f6d9b/
Hendrik Wiese

No sorry wrong post
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
Hendrik Wiese

Get-DistributionGroup | Where-Object { (Get-DistributionGroupMember –identity $_.Name).Count –lt 1 }

Please refer to http://www.howexchangeworks.com/2009/10/task-find-empty-distribution-groups-in.html for more info?
quickslvr

ASKER
well,this is is completely useless.

one more time:

i need an output which shows me if there are any users listed in any of our Distribution Lists. And if yes,who is it included in it.

is this possible?
Hendrik Wiese

All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
quickslvr

ASKER
yes,thanks. but i do not see which command would do this task
Hendrik Wiese

Hi,

1. Ok you can use anyone of the 2 options that was set out as the answer (The comments with a green border) Now copy the code below and paste it into notepad.
2. Then save the file as script.ps1
3. Open powershell and browse to the directory for example 'cd C:\'
4. In this example I would presume that you saved the file on the C:\
5. Now in Powershell type script.ps1 which will run the script.

# Initialize array with two fields:

# Distribution group, Members

$totalObj = @()

 

# Retrieve all DGs

$temp = Get-DistributionGroup -ResultSize Unlimited | 

      

       # Loop through all distribution groups

       ForEach-Object {          

      

             # Add the members of the DG to an array

             [array]$mem = Get-DistributionGroupMember -id $_     

            

             # Loop through the DG and assign each member name to the variable $member

             for ($i = 0; $i -lt $mem.Count; $i++) {

                    $member = $mem[$i].name

                   

                    # Create instance of object of type .NET

                    $obj = New-Object System.Object

      

                    # Add the name of the DG to the object

                    $obj | Add-Member -MemberType NoteProperty -Value $_.Name -Name 'Distribution Group' -Force

                   

                    # Add the member name to the object

                    $obj | Add-Member -MemberType NoteProperty -Value $member -Name 'Members' -Force -PassThru

                   

                    # Add the object to the array

                    $totalObj += $obj

             }

       }

 

# Pipe output to .csv file

$totalObj | Export-Csv -Encoding 'Unicode' c:\temp\ngtest.csv

 

The output is written like this to the csv. file:

 

"Distribution Group",Members

"All Users","Jon-Alfred Smith"

"All Users","Julie Smith"

"Windows SBS Administrators","Standard User with administration links"

"Windows SBS Administrators","Jon-Alfred Smith"

If you just want to have the name of the DG once, change this line: Only add the name the first time, when the counter is zero:

 

# Add the name of the DG to the object

if ($i -eq 0) {

$obj | Add-Member -MemberType NoteProperty -Value $_.Name -Name 'Distribution Group' -Force

}

Open in new window

quickslvr

ASKER
there are some errors by executing this code:


         Welcome to the Exchange Management Shell!

 Full list of cmdlets:          get-command
 Only Exchange cmdlets:         get-excommand
 Cmdlets for a specific role:   get-help -role *UM* or *Mailbox*
 Get general help:              help
 Get help for a cmdlet:         help <cmdlet-name> or <cmdlet-name> -?
 Show quick reference guide:    quickref
 Exchange team blog:            get-exblog
 Show full output for a cmd:    <cmd> | format-list

Tip of the day #18:

To display the list of UM IP gateway server names that are disabled for outbound
 calling and hunt groups that are associated with a UM IP gateway server, use:

 Get-UMIPGateway | ForEach {If($_.OutCallsAllowed -Eq $False){ "Gateway Name = "
 +$_.Name;ForEach ($HuntGroup In $_.Huntgroups){"Huntgroups " + $Huntgroup}}}

[PS] C:\Documents and Settings\CHAA926\Desktop># Initialize array with two field
s:
[PS] C:\Documents and Settings\CHAA926\Desktop>
[PS] C:\Documents and Settings\CHAA926\Desktop># Distribution group, Members
[PS] C:\Documents and Settings\CHAA926\Desktop>
[PS] C:\Documents and Settings\CHAA926\Desktop>$totalObj = @()
[PS] C:\Documents and Settings\CHAA926\Desktop>
[PS] C:\Documents and Settings\CHAA926\Desktop>
[PS] C:\Documents and Settings\CHAA926\Desktop>
[PS] C:\Documents and Settings\CHAA926\Desktop># Retrieve all DGs
[PS] C:\Documents and Settings\CHAA926\Desktop>
[PS] C:\Documents and Settings\CHAA926\Desktop>$temp = Get-DistributionGroup -Re
sultSize Unlimited |
>>
>>
>>
>>        # Loop through all distribution groups
>>
An empty pipe element is not allowed.
At line:1 char:54
+ $temp = Get-DistributionGroup -ResultSize Unlimited | <<<<
    + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordEx
   ception
    + FullyQualifiedErrorId : EmptyPipeElement

[PS] C:\Documents and Settings\CHAA926\Desktop>       ForEach-Object {

>>
>>
>>
>>              # Add the members of the DG to an array
>>
>>              [array]$mem = Get-DistributionGroupMember -id $_
>>
>>
>>
>>              # Loop through the DG and assign each member name to the variabl
e $member
>>
>>              for ($i = 0; $i -lt $mem.Count; $i++) {
>>
>>                     $member = $mem[$i].name
>>
>>
>>
>>                     # Create instance of object of type .NET
>>
>>                     $obj = New-Object System.Object
>>
>>
>>
>>                     # Add the name of the DG to the object
>>
>>                     $obj | Add-Member -MemberType NoteProperty -Value $_.Name
 -Name 'Distribution Group' -Force
>>
>>
>>
>>                     # Add the member name to the object
>>
>>                     $obj | Add-Member -MemberType NoteProperty -Value $member
 -Name 'Members' -Force -PassThru
>>
>>
>>
>>                     # Add the object to the array
>>
>>                     $totalObj += $obj
>>
>>              }
>>
>>        }
>>
Get-DistributionGroupMember : Cannot bind argument to parameter 'Identity' beca
use it is null.
At line:3 char:59
+              [array]$mem = Get-DistributionGroupMember -id <<<<  $_
    + CategoryInfo          : InvalidData: (:) [Get-DistributionGroupMember],
   ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,M
   icrosoft.Exchange.Management.RecipientTasks.GetDistributionGroupMember

[PS] C:\Documents and Settings\CHAA926\Desktop>
[PS] C:\Documents and Settings\CHAA926\Desktop>
[PS] C:\Documents and Settings\CHAA926\Desktop># Pipe output to .csv file
[PS] C:\Documents and Settings\CHAA926\Desktop>
[PS] C:\Documents and Settings\CHAA926\Desktop>$totalObj | Export-Csv -Encoding
'Unicode' c:\temp\ngtest.csv
[PS] C:\Documents and Settings\CHAA926\Desktop>
[PS] C:\Documents and Settings\CHAA926\Desktop>
[PS] C:\Documents and Settings\CHAA926\Desktop>
[PS] C:\Documents and Settings\CHAA926\Desktop>The output is written like this t
o the csv. file:
The term 'The' is not recognized as the name of a cmdlet, function, script file
, or operable program. Check the spelling of the name, or if a path was include
d, verify that the path is correct and try again.
At line:1 char:4
+ The <<<<  output is written like this to the csv. file:
    + CategoryInfo          : ObjectNotFound: (The:String) [], CommandNotFound
   Exception
    + FullyQualifiedErrorId : CommandNotFoundException

[PS] C:\Documents and Settings\CHAA926\Desktop>
[PS] C:\Documents and Settings\CHAA926\Desktop>
[PS] C:\Documents and Settings\CHAA926\Desktop>
[PS] C:\Documents and Settings\CHAA926\Desktop>"Distribution Group",Members
Missing expression after ','.
At line:1 char:22
+ "Distribution Group", <<<< Members
    + CategoryInfo          : ParserError: (,:String) [], ParentContainsErrorR
   ecordException
    + FullyQualifiedErrorId : MissingExpressionAfterToken

[PS] C:\Documents and Settings\CHAA926\Desktop>
[PS] C:\Documents and Settings\CHAA926\Desktop>"All Users","Jon-Alfred Smith"
All Users
Jon-Alfred Smith
[PS] C:\Documents and Settings\CHAA926\Desktop>
[PS] C:\Documents and Settings\CHAA926\Desktop>"All Users","Julie Smith"
All Users
Julie Smith
[PS] C:\Documents and Settings\CHAA926\Desktop>
[PS] C:\Documents and Settings\CHAA926\Desktop>"Windows SBS Administrators","Sta
ndard User with administration links"
Windows SBS Administrators
Standard User with administration links
[PS] C:\Documents and Settings\CHAA926\Desktop>
[PS] C:\Documents and Settings\CHAA926\Desktop>"Windows SBS Administrators","Jon
-Alfred Smith"
Windows SBS Administrators
Jon-Alfred Smith
[PS] C:\Documents and Settings\CHAA926\Desktop>
[PS] C:\Documents and Settings\CHAA926\Desktop>If you just want to have the name
 of the DG once, change this line: Only add the name the first time, when the co
unter is zero:
Missing '(' after 'if' in if statement.
At line:1 char:4
+ If  <<<< you just want to have the name of the DG once, change this line: Onl
y add the name the first time, when the counter is zero:
    + CategoryInfo          : ParserError: (OpenParenToken:TokenId) [], Parent
   ContainsErrorRecordException
    + FullyQualifiedErrorId : MissingEndParenthesisInIfStatement

[PS] C:\Documents and Settings\CHAA926\Desktop>
[PS] C:\Documents and Settings\CHAA926\Desktop>
[PS] C:\Documents and Settings\CHAA926\Desktop>
[PS] C:\Documents and Settings\CHAA926\Desktop># Add the name of the DG to the o
bject
[PS] C:\Documents and Settings\CHAA926\Desktop>
[PS] C:\Documents and Settings\CHAA926\Desktop>if ($i -eq 0) {
>>
>> $obj | Add-Member -MemberType NoteProperty -Value $_.Name -Name 'Distribution
 Group' -Force
>>
>> }
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
ASKER CERTIFIED SOLUTION
Hendrik Wiese

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Hendrik Wiese

So what I am saying is:
1. Open notepad and copy the above code into it
2. Save the file as export.ps1 in c:\windows\system32
3. No open powershell and type in .\export.ps1 and hit enter
4. This will export the output to c:\ngtest.csv

Let me know if this helps?
quickslvr

ASKER
here we go:

[PS] C:\windows>export.ps1
WARNING: Object eu.scor.local/SG/Groups/SGL Taipei has been corrupted and it is
 in an inconsistent state. The following validation errors have occurred:
WARNING: "SGL Taipei" is not valid for Alias. Valid values are: Strings formed
with characters from a to z (uppercase or lowercase), digits from 0 to 9, !, #,
 $, %, &, ', *, +, -, /, =, ?, ^, _, `, {, |, } or ~. One or more periods may
be embedded in an alias, but each one of them should be preceded and followed
by at least one of the other characters. Unicode characters from U+00A1 to
U+00FF are also valid in an alias, but they will be mapped to a best-fit
US-ASCII string in the email address which is generated from such an alias.
WARNING: Object eu.scor.local/SG/Groups/SGL India has been corrupted and it is
in an inconsistent state. The following validation errors have occurred:
WARNING: "SGL India" is not valid for Alias. Valid values are: Strings formed
with characters from a to z (uppercase or lowercase), digits from 0 to 9, !, #,
 $, %, &, ', *, +, -, /, =, ?, ^, _, `, {, |, } or ~. One or more periods may
be embedded in an alias, but each one of them should be preceded and followed
by at least one of the other characters. Unicode characters from U+00A1 to
U+00FF are also valid in an alias, but they will be mapped to a best-fit
US-ASCII string in the email address which is generated from such an alias.
WARNING: Object eu.scor.local/SG/Groups/SGL Korea has been corrupted and it is
in an inconsistent state. The following validation errors have occurred:
WARNING: "SGL Korea" is not valid for Alias. Valid values are: Strings formed
with characters from a to z (uppercase or lowercase), digits from 0 to 9, !, #,
 $, %, &, ', *, +, -, /, =, ?, ^, _, `, {, |, } or ~. One or more periods may
be embedded in an alias, but each one of them should be preceded and followed
by at least one of the other characters. Unicode characters from U+00A1 to
U+00FF are also valid in an alias, but they will be mapped to a best-fit
US-ASCII string in the email address which is generated from such an alias.
WARNING: Object eu.scor.local/SG/Groups/SGL Asia has been corrupted and it is
in an inconsistent state. The following validation errors have occurred:
WARNING: "SGL Asia" is not valid for Alias. Valid values are: Strings formed
with characters from a to z (uppercase or lowercase), digits from 0 to 9, !, #,
 $, %, &, ', *, +, -, /, =, ?, ^, _, `, {, |, } or ~. One or more periods may
be embedded in an alias, but each one of them should be preceded and followed
by at least one of the other characters. Unicode characters from U+00A1 to
U+00FF are also valid in an alias, but they will be mapped to a best-fit
US-ASCII string in the email address which is generated from such an alias.
WARNING: Object eu.scor.local/SG/Groups/SGL Taipei has been corrupted and it is
 in an inconsistent state. The following validation errors have occurred:
WARNING: "SGL Taipei" is not valid for Alias. Valid values are: Strings formed
with characters from a to z (uppercase or lowercase), digits from 0 to 9, !, #,
 $, %, &, ', *, +, -, /, =, ?, ^, _, `, {, |, } or ~. One or more periods may
be embedded in an alias, but each one of them should be preceded and followed
by at least one of the other characters. Unicode characters from U+00A1 to
U+00FF are also valid in an alias, but they will be mapped to a best-fit
US-ASCII string in the email address which is generated from such an alias.
WARNING: Object eu.scor.local/SG/Groups/SGL Taipei has been corrupted and it is
 in an inconsistent state. The following validation errors have occurred:
WARNING: "SGL Taipei" is not valid for Alias. Valid values are: Strings formed
with characters from a to z (uppercase or lowercase), digits from 0 to 9, !, #,
 $, %, &, ', *, +, -, /, =, ?, ^, _, `, {, |, } or ~. One or more periods may
be embedded in an alias, but each one of them should be preceded and followed
by at least one of the other characters. Unicode characters from U+00A1 to
U+00FF are also valid in an alias, but they will be mapped to a best-fit
US-ASCII string in the email address which is generated from such an alias.
WARNING: Object eu.scor.local/SG/Groups/SGL India has been corrupted and it is
in an inconsistent state. The following validation errors have occurred:
WARNING: "SGL India" is not valid for Alias. Valid values are: Strings formed
with characters from a to z (uppercase or lowercase), digits from 0 to 9, !, #,
 $, %, &, ', *, +, -, /, =, ?, ^, _, `, {, |, } or ~. One or more periods may
be embedded in an alias, but each one of them should be preceded and followed
by at least one of the other characters. Unicode characters from U+00A1 to
U+00FF are also valid in an alias, but they will be mapped to a best-fit
US-ASCII string in the email address which is generated from such an alias.
WARNING: Object eu.scor.local/SG/Groups/SGL Korea has been corrupted and it is
in an inconsistent state. The following validation errors have occurred:
WARNING: "SGL Korea" is not valid for Alias. Valid values are: Strings formed
with characters from a to z (uppercase or lowercase), digits from 0 to 9, !, #,
 $, %, &, ', *, +, -, /, =, ?, ^, _, `, {, |, } or ~. One or more periods may
be embedded in an alias, but each one of them should be preceded and followed
by at least one of the other characters. Unicode characters from U+00A1 to
U+00FF are also valid in an alias, but they will be mapped to a best-fit
US-ASCII string in the email address which is generated from such an alias.
WARNING: Object eu.scor.local/SG/Groups/SGL Asia has been corrupted and it is
in an inconsistent state. The following validation errors have occurred:
WARNING: "SGL Asia" is not valid for Alias. Valid values are: Strings formed
with characters from a to z (uppercase or lowercase), digits from 0 to 9, !, #,
 $, %, &, ', *, +, -, /, =, ?, ^, _, `, {, |, } or ~. One or more periods may
be embedded in an alias, but each one of them should be preceded and followed
by at least one of the other characters. Unicode characters from U+00A1 to
U+00FF are also valid in an alias, but they will be mapped to a best-fit
US-ASCII string in the email address which is generated from such an alias.
WARNING: Object eu.scor.local/SG/Groups/SGL India has been corrupted and it is
in an inconsistent state. The following validation errors have occurred:
WARNING: "SGL India" is not valid for Alias. Valid values are: Strings formed
with characters from a to z (uppercase or lowercase), digits from 0 to 9, !, #,
 $, %, &, ', *, +, -, /, =, ?, ^, _, `, {, |, } or ~. One or more periods may
be embedded in an alias, but each one of them should be preceded and followed
by at least one of the other characters. Unicode characters from U+00A1 to
U+00FF are also valid in an alias, but they will be mapped to a best-fit
US-ASCII string in the email address which is generated from such an alias.
WARNING: Object eu.scor.local/SG/Groups/GED AP has been corrupted and it is in
an inconsistent state. The following validation errors have occurred:
WARNING: "GED AP" is not valid for Alias. Valid values are: Strings formed with
 characters from a to z (uppercase or lowercase), digits from 0 to 9, !, #, $,
%, &, ', *, +, -, /, =, ?, ^, _, `, {, |, } or ~. One or more periods may be
embedded in an alias, but each one of them should be preceded and followed by
at least one of the other characters. Unicode characters from U+00A1 to U+00FF
are also valid in an alias, but they will be mapped to a best-fit US-ASCII
string in the email address which is generated from such an alias.
WARNING: Object eu.scor.local/SG/Groups/SGL Korea has been corrupted and it is
in an inconsistent state. The following validation errors have occurred:
WARNING: "SGL Korea" is not valid for Alias. Valid values are: Strings formed
with characters from a to z (uppercase or lowercase), digits from 0 to 9, !, #,
 $, %, &, ', *, +, -, /, =, ?, ^, _, `, {, |, } or ~. One or more periods may
be embedded in an alias, but each one of them should be preceded and followed
by at least one of the other characters. Unicode characters from U+00A1 to
U+00FF are also valid in an alias, but they will be mapped to a best-fit
US-ASCII string in the email address which is generated from such an alias.
WARNING: Object eu.scor.local/FR/Communication Lists/SCOR INDIA has been
corrupted and it is in an inconsistent state. The following validation errors
have occurred:
WARNING: "SCOR INDIA" is not valid for Alias. Valid values are: Strings formed
with characters from a to z (uppercase or lowercase), digits from 0 to 9, !, #,
 $, %, &, ', *, +, -, /, =, ?, ^, _, `, {, |, } or ~. One or more periods may
be embedded in an alias, but each one of them should be preceded and followed
by at least one of the other characters. Unicode characters from U+00A1 to
U+00FF are also valid in an alias, but they will be mapped to a best-fit
US-ASCII string in the email address which is generated from such an alias.
WARNING: Object eu.scor.local/FR/Users/Contacts/CHODRON de Courcel Georges has
been corrupted and it is in an inconsistent state. The following validation
errors have occurred:
WARNING: "Georges(Censeur)CHODRONdeCourcel" is not valid for Alias. Valid
values are: Strings formed with characters from a to z (uppercase or
lowercase), digits from 0 to 9, !, #, $, %, &, ', *, +, -, /, =, ?, ^, _, `, {,
 |, } or ~. One or more periods may be embedded in an alias, but each one of
them should be preceded and followed by at least one of the other characters.
Unicode characters from U+00A1 to U+00FF are also valid in an alias, but they
will be mapped to a best-fit US-ASCII string in the email address which is
Hendrik Wiese

Did anything export?
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
Hendrik Wiese

All the alias's above has got spaces in them which is not allowed. So go to the following DL's and remove the spaces in the alias field:
SGL Taipei
SGL India
SGL Korea
SGL Asia
SGL Taipei
GED AP
SCOR INDIA

And remove the () on the following one:
Georges(Censeur)CHODRONdeCourcel
quickslvr

ASKER
what does that script exactly do?
does it create any new users?
Hendrik Wiese

Aai...

It exports all Distribution Lists with and their members to a CSV file called ngtest.csv on the C:\

The output looks like the following and when you open it with excel you will have everything in a nice format:

#TYPE System.Object
"Distribution Group","Members"
"GroupTest","Hendrik Wiese"
"GroupTest2","Hendrik Wiese","User Two"

It is what you asked for it to do.
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
Hendrik Wiese

So you would be able to see which groups have got no users associated with them.
quickslvr

ASKER
the ngtest.csv  is empty...
Hendrik Wiese

Did you fix the Alias's as mentioned above? I have tested the script on my side and everything works fine.
Your help has saved me hundreds of hours of internet surfing.
fblack61
quickslvr

ASKER
yes,now its fine.

thanks a lot!