I have a script that will drill down a specific OU, to sub OU's and then list all of the users and the groups that user is a member of. It works well but i have a problem, i cannot format the results correctly.
What i get back looks like this:
CN=Testing3,OU=NA,OU=Portal,DC=TestDomain,DC=com
, , ,CN=GPI,OU=Portal,DC=TestDomain,DC=com
, , ,CN=Primary Global,OU=Portal,DC=TestDomain,DC=com
, , ,CN=Ariba,OU=Portal,DC=TestDomain,DC=com
(I placed the ", , ," just so i could find the break in the information.)
what i would like to have is this:
NA, Testing3, GPI
NA, Testing3, Primary Global
NA, Testing3, Ariba
I just can't figure out how to trim the information. If anyone could point me in the right direction i would greatly appreciate it. Thanks.
Below is the code that returns the results above:
PS - (I don't remember where i borrowed the code from so if it is from someone here thanks.)
Option Explicit
On Error Resume Next
Const E_ADS_PROPERTY_NOT_FOUND = &h8000500D
Dim objDSE, strDefaultDN, strDN, objContainer
'Create the Text file
Dim fs, res
Set fs = WScript.CreateObject("Scripting.FileSystemObject"
Set res = fs.CreateTextFile("c:\Users.txt", True)
res.Writeline ("Users details"
'Select the current Domain
Set objDSE = GetObject("LDAP://rootDSE"
strDefaultDN = objDSE.Get("defaultNamingContext"
strDN = strDefaultDN
'This is just a loop that will return all of the users and OU's
Set objContainer = GetObject("LDAP://" & strDN)
Call ListUsers(objContainer)
Sub ListUsers(objADObject)
Dim objChild, arrMemberOf, item
For Each objChild in objADObject
Select Case objChild.Class
Case "user"
res.Writeline objChild.Get("DistinguishedName"
arrMemberOf = objChild.GetEx("memberOf"
If Err.Number = E_ADS_PROPERTY_NOT_FOUND Then
res.Writeline "The memberOf attribute is not set."
Else
res.Writeline " "
For each item in arrMemberOf
res.Writeline ", , ," & Item
Next
End If
Case "organizationalUnit" , "container"
Call ListUsers(objChild)
End select
Next
End Sub
What i get back looks like this:
CN=Testing3,OU=NA,OU=Portal,DC=TestDomain,DC=com
, , ,CN=GPI,OU=Portal,DC=TestDomain,DC=com
, , ,CN=Primary Global,OU=Portal,DC=TestDomain,DC=com
, , ,CN=Ariba,OU=Portal,DC=TestDomain,DC=com
(I placed the ", , ," just so i could find the break in the information.)
what i would like to have is this:
NA, Testing3, GPI
NA, Testing3, Primary Global
NA, Testing3, Ariba
I just can't figure out how to trim the information. If anyone could point me in the right direction i would greatly appreciate it. Thanks.
Below is the code that returns the results above:
PS - (I don't remember where i borrowed the code from so if it is from someone here thanks.)
Option Explicit
On Error Resume Next
Const E_ADS_PROPERTY_NOT_FOUND = &h8000500D
Dim objDSE, strDefaultDN, strDN, objContainer
'Create the Text file
Dim fs, res
Set fs = WScript.CreateObject("Scripting.FileSystemObject"
Set res = fs.CreateTextFile("c:\Users.txt", True)
res.Writeline ("Users details"
'Select the current Domain
Set objDSE = GetObject("LDAP://rootDSE"
strDefaultDN = objDSE.Get("defaultNamingContext"
strDN = strDefaultDN
'This is just a loop that will return all of the users and OU's
Set objContainer = GetObject("LDAP://" & strDN)
Call ListUsers(objContainer)
Sub ListUsers(objADObject)
Dim objChild, arrMemberOf, item
For Each objChild in objADObject
Select Case objChild.Class
Case "user"
res.Writeline objChild.Get("DistinguishedName"
arrMemberOf = objChild.GetEx("memberOf"
If Err.Number = E_ADS_PROPERTY_NOT_FOUND Then
res.Writeline "The memberOf attribute is not set."
Else
res.Writeline " "
For each item in arrMemberOf
res.Writeline ", , ," & Item
Next
End If
Case "organizationalUnit" , "container"
Call ListUsers(objChild)
End select
Next
End Sub