Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsWindows Server 2003Windows 2000Windows NTSmall Business ServerVirtual ServerExchange ServerIISHost Integration ServerISA ServerSMSWSUSMOMWindows Media ServerSecurityCertification
Related Topics
SQL ServerMS WindowsMS OfficePC HardwareMore Topics ...

Windows Server Forum / Exchange Server / Tools / July 2008

Tip: Looking for answers? Try searching our database.

PowerShell Query to find all DLs that a contact object is a member

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
JF - 10 Jul 2008 17:54 GMT
Can someone tell me the best way to determine what Distribution List a
contact object is member of?

Thanks
Bharat Suneja [MSFT] - 10 Jul 2008 22:31 GMT
$contact = get-contact "foo@somedomain.com"; get-distributiongroup | foreach
{$dg = $_ ;  get-distributiongroupmember $dg | foreach {if
($_.identity -like $contact.identity) {"Member of " + $dg} } }

There's likely a shorter way to do this...

Signature

Bharat Suneja
Microsoft Corporation
blog: exchangepedia.com/blog

This posting is provided "AS IS" with no warranties, and confers no
rights. Please do not send email directly to this alias. This alias is for
newsgroup purposes only.
----------------------------

> Can someone tell me the best way to determine what Distribution List a
> contact object is member of?
>
> Thanks
JF - 11 Jul 2008 14:57 GMT
Thanks for the fast reply!
I ran that script and it was asking for more input. I repleace
foo@somedomain.com with my user. Is there something more I must input? It was
asking for input at process 1 and 2.

[PS] C:\Documents and Settings\adam>$contact = get-contact "she@go
.com"; get-distributiongroup | foreach

cmdlet foreach at command pipeline position 2
Supply values for the following parameters:
Process[0]: {$dg = $_ ;  get-distributiongroupmember $dg | foreach {if
Process[1]: ($_.identity -like $contact.identity) {"Member of " + $dg} } }
Process[2]:
ForEach-Object : Cannot bind parameter 'Process'. Cannot convert value "{$dg =
$_ ;  get-distributiongroupmember $dg | foreach {if " to type
"System.Managemen
t.Automation.ScriptBlock". Error: "Invalid cast from 'System.String' to
'System
.Management.Automation.ScriptBlock'."
At line:1 char:76
+ $contact = get-contact "she@go.com"; get-distributiongroup | foreach
<<<<

> $contact = get-contact "foo@somedomain.com"; get-distributiongroup | foreach
> {$dg = $_ ;  get-distributiongroupmember $dg | foreach {if
[quoted text clipped - 6 lines]
> >
> > Thanks
Bharat Suneja [MSFT] - 11 Jul 2008 20:04 GMT
Tested this again - works for me. Not sure about the errors.
This is exactly how my query is constructed/typed (all on one line):

$contact = get-contact "foo@somedomain.com"; Get-DistributionGroup | foreach
{$dg = $_ ; Get-DistributionGroupMember $dg | foreach {if ($_.identity -like
$contact.identity) {"Member of : " +  $dg} }}
Signature

Bharat Suneja
Microsoft Corporation
blog: exchangepedia.com/blog

This posting is provided "AS IS" with no warranties, and confers no
rights. Please do not send email directly to this alias. This alias is for
newsgroup purposes only.
----------------------------

> Thanks for the fast reply!
> I ran that script and it was asking for more input. I repleace
[quoted text clipped - 32 lines]
>> >
>> > Thanks
Bharat Suneja [MSFT] - 11 Jul 2008 20:35 GMT
Taking a second look - don't think you typed it all on a single line. If you
snip the command at foreach, it'll ask you for additional input (the
process[0], process[1] etc.).

Signature

Bharat Suneja
Microsoft Corporation
blog: exchangepedia.com/blog

This posting is provided "AS IS" with no warranties, and confers no
rights. Please do not send email directly to this alias. This alias is for
newsgroup purposes only.
----------------------------

> Tested this again - works for me. Not sure about the errors.
> This is exactly how my query is constructed/typed (all on one line):
[quoted text clipped - 39 lines]
>>> >
>>> > Thanks
JF - 12 Jul 2008 03:36 GMT
Thank you very much!
I retyped it in and all is well!

> $contact = get-contact "foo@somedomain.com"; get-distributiongroup | foreach
> {$dg = $_ ;  get-distributiongroupmember $dg | foreach {if
[quoted text clipped - 6 lines]
> >
> > Thanks
Bharat Suneja [MSFT] - 20 Jul 2008 19:53 GMT
The script (with some enhancements) is available here. You can provide one
or more recipients as command-line input and get a list of groups the
recipient is a member of.

Signature

Bharat Suneja
Microsoft Corporation
blog: exchangepedia.com/blog

This posting is provided "AS IS" with no warranties, and confers no
rights. Please do not send email directly to this alias. This alias is for
newsgroup purposes only.
----------------------------

> Thank you very much!
> I retyped it in and all is well!
[quoted text clipped - 10 lines]
>> >
>> > Thanks
Bharat Suneja [MSFT] - 20 Jul 2008 19:54 GMT
Prev message got sent without the link:

The script (with some enhancements) is available here. You can provide one
or more recipients as command-line input and get a list of groups the
recipient is a member of.

Script: Listing Distribution Groups a recipient is a member of
http://exchangepedia.com/blog/2008/07/script-listing-distribution-groups.html

Signature

Bharat Suneja
Microsoft Corporation
blog: exchangepedia.com/blog

This posting is provided "AS IS" with no warranties, and confers no
rights. Please do not send email directly to this alias. This alias is for
newsgroup purposes only.
----------------------------

> Thank you very much!
> I retyped it in and all is well!
[quoted text clipped - 10 lines]
>> >
>> > Thanks
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.