I'm working on a script that will list the members of an OU and a group and then print the common members to a file. I have the group query working, but the OU query is where my problem lies. In order to break the problem down I've written the OU code as a seperate script. Depending on how I've written the query I've gotten the following errors:
Null: Exception occurred
Table doesn't exist
Provider: One or more error occurred during the processing of command.
I THINK my problem lies with the fact that I need to search on the uniquely named OU such as IT Department, and then have it drill down one step further to get to the non-unique OU Users below it. The group search was easy because they're all unique names.
Domain--Departments OU---IT Dept OU--Programmers OU--Listed under here are: Computers OU and Users OU
What would be the query to list the members of the non-uniquely named "Users OU" under Programmers since a Users OU exists at the bottom of every dept OU? Is there some way that I can list the OU as Programmers\Users or ????
I've enclosed the group list code that works. I ASSUME that I should be doing something very similar for the OU portion.
Thanks in advance,
strGroup = InputBox("Please put the desired group name:","Group name")
strFileName = "c:\members_of_" & strGroup & ".txt"
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objOutputFile = objFSO.OpenTextFile(strFileName, 2, true, 0)
objOutputFile.WriteLine "Members of group " & strGroup
Set oConnection = CreateObject("ADODB.Connection")
Set oCommand = CreateObject("ADODB.Command")
oConnection.Provider = "ADsDSOObject"
oConnection.Open "Active Directory Provider"
Set oCommand.ActiveConnection = oConnection
sQuery = "SELECT cn, distinguishedName From 'LDAP://dc=xxxx,dc=xx,dc=xxxxx,dc=xxx' where cn='" & strGroup & "'"
oCommand.CommandText = sQuery
Set oResults = oCommand.Execute
On Error Resume Next
Set objGroup = GetObject _
("LDAP://" & oResults.Fields("distinguishedName"))
arrMemberOf = objGroup.GetEx("member")
For Each strMember in arrMemberOf
'this portion will only write the cn of the user or group
strlength = InStr(strMember,",") - Instr(strMember,"CN=")
msgStart = Instr(strMember,"CN=")
msgValue = Mid(strMember,msgStart,strlength)
' WScript.echo Right(msgValue, Len(msgValue)-3)
objOutputFile.WriteLine Right(msgValue, Len(msgValue)-3)
'This portion writes the whole dn-string
WScript.Echo ("Log created and updated. ") & strFileName
'End of script -----------------