I found a script from some ms site that list groups that a user are member of, even nested groups. But that I want to be able to do with this script is not having specify which OU the user resides in. I want to search for a user in the whole domain and see what groups the user are member of. Any idea how to do this?
Thx in advance
// Ola
Code:
' Commands to bind to AD and extract domain name
Set objRootLDAP = GetObject("LDAP://RootDSE")
strDNSDomain = objRootLDAP.Get("DefaultNamingContext")
Set FileSystem = WScript.CreateObject("Scripting.FileSystemObject")
Set OutPutFile = FileSystem.CreateTextFile("test.txt", True)
strUser ="cn=test,"
strOU ="OU=test,"
strLDAP ="LDAP://" & strUser & strOU & strDNSDomain
Set objUser = GetObject(strLDAP)
Set colGroups = objUser.Groups
For Each objGroup in colGroups
'Wscript.Echo objGroup.CN
GetNested(objGroup)
Next
Function GetNested(objGroup)
On Error Resume Next
colMembers = objGroup.GetEx("memberOf")
For Each strMember in colMembers
strPath = "LDAP://" & strMember
Set objNestedGroup = GetObject(strPath)
' WScript.Echo objNestedGroup.CN
OutputFile.Writeline objGroup.CN
GetNested(objNestedGroup)
Next
End Function
Thx in advance
// Ola