Member of Which DG
Hello,
I use Exchange 2007 and would like to know of I could get from my identity "Graig" the Distribution groups where I am member of?
Thanks ,
G
August 26th, 2010 7:10pm
I am sure you're asking something different because the way you can see what groups you're a member of is as simple as finding yourself in the GAL, double clicking and then going to the Member Of tab.
Is that what you were really asking?
"Graiggoriz" wrote in message
news:5ddb996d-bbba-4a3d-85cb-c15ef497cf2f...
Hello,
I use Exchange 2007 and would like to know of I could get from my identity "Graig" the Distribution groups where I am member of?
Thanks ,
G
Mark Arnold, Exchange MVP.
Free Windows Admin Tool Kit Click here and download it now
August 26th, 2010 7:25pm
foreach ($dl in get-distributiongroup){if ((get-distributiongroupmember $dl |% {$_.name}) -contains "Graig"){$dl.name}}[string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "
August 26th, 2010 7:31pm
Try this script:
On Error Resume Next
Const ADS_SCOPE_SUBTREE = 2
Const ForAppending = 8
Const ForReading = 1
Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCommand.ActiveConnection = objConnection
objCommand.Properties("Page Size") = 1000
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
Set objRootDSE = GetObject("LDAP://RootDSE")
'Get domain
strDNSDomain = objRootDSE.Get("defaultNamingContext")
strBase = "<LDAP://" & strDNSDomain & ">"
strFilter = "(&(objectCategory=user))"
'List all attributes you will require
strAttributes = "distinguishedName,sAMAccountName,groupType"
Set objFSO = CreateObject("Scripting.FileSystemObject")
set Reportfile1 =objFSO.OpenTextFile("Report.txt", ForAppending, True)
Set SrvList = objFSO.OpenTextFile("User_List.txt", ForReading)
i = 0
Do Until SrvList.AtEndOfStream
strname=srvlist.readline
objCommand.CommandText = _
"SELECT DisplayName,sAMAccountName,memberof,distinguishedName,managedby,mail,notes FROM 'LDAP://dc=domain,dc=com' WHERE objectCategory='user' " & _
"AND displayname='" & strName & "'"
Set objRecordSet = objCommand.Execute
DN2 = objRecordSet.Fields("distinguishedName").Value
set objUser = GetObject("LDAP://" & DN2)
objMemberOf = objUser.getex("memberOf")
for each objGroup in objMemberof
wscript.echo objGroup
wscript.echo objGroup.displayname
next
Loop
objRecordset.Close
objConnection.Close
this will use the memberof attribute of the user and loop thru them.Thiyagu | MCTS/MCITP - Exchange 2007 | MCSE 2003[Messaging] | http://www.myExchangeWorld.com. This posting is provided "AS IS" with no warranties, and confers no rights.
Free Windows Admin Tool Kit Click here and download it now
August 26th, 2010 7:46pm
Hello Mjolinor,
The shell command:
foreach ($dl in get-distributiongroup) {if ((get-distributiongroupmember $dl |% {$_.name}) -contains"Graig"){$dl.name}}
Doesn't work. Maybe a missing space ..
August 26th, 2010 7:59pm
I tested it on my system using my account. The only thing I replaced was the name. It may be a name field mismatch. Is "Graig" the display name?[string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "
Free Windows Admin Tool Kit Click here and download it now
August 26th, 2010 8:08pm
In fact I used my "SamAccountName" and it doesn't work. but it work with my display name now!!
Any way to do it with the SamAccountName instead?
August 26th, 2010 8:20pm
foreach ($dl in get-distributiongroup) {if ((get-distributiongroupmember $dl |% {$_.samaccountname}) -contains"Graig"){$dl.name}}[string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "
Free Windows Admin Tool Kit Click here and download it now
August 26th, 2010 8:24pm
It is just PERFECT!!!!
Would it be possible to have the DG where I am ACCEPTMESSAGESONLYFROM ?? (it would be really great!!)
August 26th, 2010 8:45pm
It's possible but it will be more complicated. The acceptmessagesonlyfrom contains a different obect type than what get-distributiongroupmember returns, and it doesn't include a samaccountname, so if you still want to use samaccountname, there'll
have to be some intermediate name resolution. [string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "
Free Windows Admin Tool Kit Click here and download it now
August 26th, 2010 9:10pm
I don't mind if I need to use the displayname instead. Ad long as it allows me to get the DGs where I have the "acceptmessagesonlyfrom".
August 26th, 2010 9:12pm
Not tested:
foreach ($dl in get-distributiongroup) {if (($dl.acceptmessagesonlyfrom |% {$_.name}) -contains"Graig"){$dl.name}}
Also note this will only find groups you've been explicitly added to the acceptmessagesonlyfrom list. That list can also include other DLs. It will not check the membership of those DLs for your name.[string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "
Free Windows Admin Tool Kit Click here and download it now
August 26th, 2010 9:24pm
TESTED and it does exactly what I was expected!
Thank you so much! you're the best!!
August 26th, 2010 9:36pm