Hi Guys,
I have been given a bit of a complicated task. Well, for me it is anyway.
I am looking for a way to query an Active Directory group for computer accounts, export the computer names to text files and append the full domain name to each computer name.
There is a limit of max 200 computers in each text file, and it has to be in alphabetical order.
I hope someone can help me with this task.
Query AD Group
Re: Query AD Group
Maybe? This comes from an old coworkers library but I've never personally used it.
Code: Select all
GetMembersOfADGroup(_Group, _Type = "both") ; _Type can be user (return only users of the group), group (return only groups in this group) or both.
{
MembersOfGroup := Object()
objRootDSE := ComObjGet("LDAP://rootDSE")
strDomain := objRootDSE.Get("defaultNamingContext")
strADPath := "LDAP://" . strDomain
objDomain := ComObjGet(strADPath)
objConnection := ComObjCreate("ADODB.Connection")
objConnection.Open("Provider=ADsDSOObject")
objCommand := ComObjCreate("ADODB.Command")
objCommand.ActiveConnection := objConnection
StringLeft, GroupNameStart, _Group, 3
StringUpper, GroupNameStart, GroupNameStart
If GroupNameStart != "CN=" ; We were given a simple name for the group so we find the distinguished name.
{
_Group := FindDistinguishedName(_Group)
}
LDAPSearchString := "<" . strADPath . ">;"
IfEqual, _Type,user
{
LDAPSearchString .= "(&(&(&(memberOf=" . _Group . ")(objectCategory=user)(objectClass=user))))"
}
IfEqual, _Type,group
{
LDAPSearchString .= "(&(objectCategory=group)(memberOf=" . _Group . "))"
}
IfEqual, _Type,both
{
LDAPSearchString .= "(memberOf=" . _Group . ")"
}
LDAPSearchString .= ";sAMAccountName;subtree"
objCommand.CommandText := LDAPSearchString
objRecordSet := objCommand.Execute
objRecordCount := objRecordSet.RecordCount
objOutputVar :=
x = 0
MemberGroups =
While !objRecordSet.EOF
{
sAMAccountName := objRecordSet.Fields.Item("sAMAccountName").value
;sAMAccountType := objRecordSet.Fields.Item("sAMAccountType").value
If MemberGroups
{
MemberGroups := MemberGroups . "`n"
}
MemberGroups := MemberGroups . sAMAccountName
objRecordSet.MoveNext
}
objRelease(objRootDSE)
objRelease(objDomain)
objRelease(objConnection)
objRelease(objCommand)
return MemberGroups
}
Who is online
Users browsing this forum: Chunjee, Joey5, Whazzzzzup15 and 280 guests