Try this, works in my environment, YMMV.  Script may not be efficient, I'm 
still a n00b.

I put the error control in there because our Security team keeps user accounts 
around, but terms mbxs, so there are still references to them. Play with and 
without it.
I also added contacts in there because I do stuff with contacts for internal 
applications that send mail unauthenticated but don't want DL's to be wide open.

Watch for wrappage.
#****************************************************
$AdminSessionADSettings.ViewEntireForest = $true
$ErrorActionPreference ="SilentlyContinue"
$blah = (Get-DistributionGroup -ResultSize unlimited | where 
{($_.AcceptMessagesOnlyFrom -ne "") -or ($_.AcceptMessagesOnlyFromDLMembers -ne 
"")})
foreach ($obj in $blah)
{
 write-host -foregroundcolor green $obj
 $users = (Get-DistributionGroup $obj).AcceptMessagesOnlyFrom
 $DL = (Get-DistributionGroup $obj).AcceptMessagesOnlyFromDLMembers
 foreach ($Recip in $users)
  {
   $type = (get-recipient $Recip).recipientType
    if ($type -eq "UserMailbox")
     {
      Write-host " User: "$Recip.Name
     }
    ElseIf ($type -eq "MailContact")
     {
      $conName = (get-mailcontact $Recip).Name
      Write-host -foregroundcolor Yellow " Contact: "$conName
     }
  }
 If ($DL -ne "")
  {
   Foreach ($DLobj in $DL)
    {
     $grpName = (Get-Group $DLobj).Name
     Write-host -foregroundcolor Darkred " Group: "$grpName
    }
  }

 Write-host ""
}
$blah.count
#****************************************************

Thanks,
- JB

From: Barsodi.John [mailto:john.bars...@igt.com]
Sent: Friday, July 24, 2009 8:02 AM
To: MS-Exchange Admin Issues
Subject: RE: Distribution List question

I see what you're saying Rob on the nested DL.  Will look at that after my 
morning meeting.

Thanks,
- JB

From: Barsodi.John [mailto:john.bars...@igt.com]
Sent: Friday, July 24, 2009 7:14 AM
To: MS-Exchange Admin Issues
Subject: RE: Distribution List question

True.  Wouldn't be hard to add the FromDLMembers Attribute.  He didn't 
specifically ask for it so I didn't include it.  I had it in my original though.

If it's got nested DL's, those nested DL's will be in the output as a normal 
DL...

Thanks,
- JB

From: Campbell, Rob [mailto:rob_campb...@centraltechnology.net]
Sent: Friday, July 24, 2009 5:23 AM
To: MS-Exchange Admin Issues
Subject: RE: Distribution List question

That may not give good results.

It looks like individual permissions to send to the DL are kept in that 
attribute, but there's another one for DL's - AcceptMessagesOnlyFromDLMembers.  
To get a complete list of who has permissions to send to the DL, you'll need to 
check to see if there's any DLs listed there, and then retrieve the list of 
members.  If it's got nested DL's, you'll have to recurse through the group 
memberships.

________________________________
From: Barsodi.John [mailto:john.bars...@igt.com]
Sent: Thursday, July 23, 2009 6:53 PM
To: MS-Exchange Admin Issues
Subject: RE: Distribution List question

This works.  Just paste it into a .ps1 file and run.
Just ran in my environment as I was curious about something similar on our 
1100+ DL's.
You can mess with the output if you want it to a text file pretty easily using 
add-content cmdlet if you wanted to do csv or tsv files.

*******************
$blah = (Get-DistributionGroup -ResultSize unlimited | where 
{$_.AcceptMessagesOnlyFrom -ne ""})
foreach ($obj in $blah)
{
 write-host -foregroundcolor yellow $obj
 $users = (Get-DistributionGroup $obj).AcceptMessagesOnlyFrom
 foreach ($mbx in $users)
  {
   Write-host " " $mbx.Name
  }
 Write-host ""
}
*******************

Thanks,
- JB

From: Brown, Larry [mailto:larry.br...@dplinc.com]
Sent: Thursday, July 23, 2009 1:28 PM
To: MS-Exchange Admin Issues
Subject: Distribution List question

Exchange 2007 SP1

I have a request from upper management:
Which DL's have Message restrictions, Accept Messages: Only From: activated, 
and who has permission to send to each one.

1: Is there a way to pull a list of DL's in the Exchange Management Shell that 
have this activated?

2: Is there a way to pull a list of the users in the EMS for each DL that has 
this activated?

The closest I've come to the second question was to use:

Get-DistributionGroup -Identity "DLname" | format-list | out-file c:\results.txt

The problem with this is it only gives me 17 or 18 names.  On our company wide 
DL there are about 30 names.

Short of going through the DL's and looking at each one (shudders) and typing 
out the names (groan)...is there a way to do this is EMS?

 Larry C. Brown
    LAN/WAN CS Support
 Dayton Power & Light


**************************************************************************************************

Note:

The information contained in this message may be privileged and confidential and

protected from disclosure.  If the reader of this message is not the intended

recipient, or an employee or agent responsible for delivering this message to

the intended recipient, you are hereby notified that any dissemination,

distribution or copying of this communication is strictly prohibited. If you

have received this communication in error, please notify us immediately by

replying to the message and deleting it from your computer.

**************************************************************************************************

Reply via email to