Interestingly, mine had a bug...
ManagedBy can be: [a] empty, [b] a single value, or [c] an array of values
My solution only properly handles [a], and [b].
So...we have to get a little smarter, and I wanted to make the formatting a
little nicer anyway. So that's below (I would consider this a "somewhat
advanced" solution - it uses the format operator and embedded pipelines). To
make it advanced would only require the addition of a delegate function to do
the formatting, so the formatting wouldn't have to be repeated on each
"manager" line.
A lesson learned here is this: to get q-and-d results, you can get by with a
few lines of PowerShell. If you want "production quality", then you'll still
need "production effort". It'll still be a quarter the size of doing it in
vbscript... :-P
get-distributiongroup -resultsize unlimited |% {
$group = $_
"Group Name & Identity: {0}, {1}" -f $group.Name,
$group.Identity
$managedBy = $group.ManagedBy
if( $managedBy.Count -gt 1 )
{
[bool]$first = $true
foreach( $manager in $managedBy )
{
if( $first )
{
"Group
managers: {0}, {1}" -f $manager.Name, ($manager.Parent.ToString() + "/" +
$manager.RDN.ToString().SubString(3))
$first = $false
}
else
{
"
{0}, {1}" -f $manager.Name, ($manager.Parent.ToString() + "/" +
$manager.RDN.ToString().SubString(3))
}
}
}
elseif( $managedBy.Count -gt 0 )
{
$manager = $managedBy[0]
"Group manager: {0}, {1}" -f $manager.Name,
($manager.Parent.ToString() + "/" + $manager.RDN.ToString().SubString(3))
}
"Members:"
Get-DistributionGroupMember -Identity $group.Identity
-ResultSize Unlimited |% {
foreach( $member in $_ )
{
"`t$($member.Name)"
}
}
"---"
}
Regards,
Michael B. Smith
Consultant and Exchange MVP
http://TheEssentialExchange.com
From: Steven Peck [mailto:[email protected]]
Sent: Wednesday, August 18, 2010 3:35 PM
To: NT System Admin Issues
Subject: Re: Generating report for Exchange Distribution groups?
Different tack..... exploration rather then answer.
The PowerShell team tries hard to make cmdlet names 'discoverable' so
the Exchange module is a snapin and has 2 elements so this will get all the
Exchange cmdlets loaded
Get-Command -Module Microsoft.Exchange.*
or you can guess by the name distribution group
Get-Command *distri*
Get-Command *group*
Either way this will get you to two commands
Get-DistributionGroup
Get-DistributionGroupMember
Using help to get examples and Get-member to see what is available
help Get-DistributionGroup -examples # (turns out to be sort of useless on
this command)
Get-DistributionGroup 'some group' | Get-Member # (more useful)
We see a managed by and Name property
So now you have the main command (get-distributiongroup) and need to expand it.
Yay foreach-object (alias % expands to foreach-object) and do similiar
Get-Memeber for the Get-DistributionGroupMember
Now Micheal's one liner is awesome and actually more useful then my quick try
(you can pipe it to out-text) but I can't quite get there that fast yet. If
the process is what caught you out, hopefully this will be helpful in a
different way then his script.
Link to cool ebook: http://powershell.com/cs/blogs/ebook/
Have fun,
Steven Peck
http://www.blkmtn.org
On Wed, Aug 18, 2010 at 12:11 PM, Steven Peck
<[email protected]<mailto:[email protected]>> wrote:
No surprise, Micheals is better then mine. SO much for beating him :)
On Wed, Aug 18, 2010 at 12:03 PM, Greg Olson
<[email protected]<mailto:[email protected]>> wrote:
Awesome, I will give this a shot.
Thanks MBS!
-Greg
-----Original Message-----
From: Michael B. Smith
[mailto:[email protected]<mailto:[email protected]>]
Sent: Wednesday, August 18, 2010 12:01 PM
To: NT System Admin Issues
Subject: RE: Generating report for Exchange Distribution groups?
Ehhhh. You might also need a couple of resultsize parameters there, depending
on the size of your organization. (I just ran it at a larger customer of mine
and ran into this.)
get-distributiongroup -resultsize unlimited |% {
$group = $_;
"Name: $($group.Name), ManagedBy: $($group.ManagedBy), Identity:
$($group.Identity)"
$members = Get-DistributiongroupMember -identity $group.Identity
-resultsize unlimited;
foreach ($member in $members) {
"`t$($member.Name)"
}
}
Regards,
Michael B. Smith
Consultant and Exchange MVP
http://TheEssentialExchange.com
-----Original Message-----
From: Michael B. Smith
[mailto:[email protected]<mailto:[email protected]>]
Sent: Wednesday, August 18, 2010 2:55 PM
To: NT System Admin Issues
Subject: RE: Generating report for Exchange Distribution groups?
[PS] C:\>get-distributiongroup |% {
>> $group = $_;
>> "Name: $($group.Name), ManagedBy: $($group.ManagedBy), Identity:
>> $($group.Identity)"
>> $members = Get-DistributiongroupMember -identity $group.Identity;
>> foreach ($member in $members) {
>> "`t$($member.Name)"
>> }
>> }
>>
Name: j-and-m, ManagedBy: smithcons.local/Users/Administrator, Identity:
smithcons.local/Users/j-and-m
Michael B. Smith
Jacqui
...
Etc.
...
Regards,
Michael B. Smith
Consultant and Exchange MVP
http://TheEssentialExchange.com
-----Original Message-----
From: Greg Olson [mailto:[email protected]<mailto:[email protected]>]
Sent: Wednesday, August 18, 2010 2:48 PM
To: NT System Admin Issues
Subject: Generating report for Exchange Distribution groups?
All,
Is there any way to generate a report that lists out all of our Distribution
groups, along with the members and owners of the lists? I see how to generate a
listing of the groups, but not a way to have it put the members of each group
and the owners as well.
I'm sure there is probably a PowerShell way of doing this, but my ps skills are
weak and Google Fu is failing today. This is on Exchange 2007 and Outlook 2010.
Thanks in advance for any help!
-Greg
~ Finally, powerful endpoint security that ISN'T a resource hog! ~ ~
<http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/> ~
~ Finally, powerful endpoint security that ISN'T a resource hog! ~ ~
<http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/> ~
~ Finally, powerful endpoint security that ISN'T a resource hog! ~ ~
<http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/> ~
~ Finally, powerful endpoint security that ISN'T a resource hog! ~
~ <http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/> ~
~ Finally, powerful endpoint security that ISN'T a resource hog! ~
~ <http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/> ~