I have a script where i am able to return distinguished names of users in a domain (eg. CN=user.name,OU=NA,OU=Portal,DC=Staging,DC=com) But what i want is just 'user.name - NA - Portal'.
Does anyone know how i can parse this information? the code is pasted below. I modified it slightly from some sample scripts i have. Thanks for the help.
----Begin Code Paste----
Option Explicit
Dim objDSE, strDefaultDN, strDN, objContainer, objChild
Dim fs, res
Set fs = WScript.CreateObject("Scripting.FileSystemObject"
Set res = fs.CreateTextFile("c:\Users.txt", True)
res.Writeline ("Users details"
Set objDSE = GetObject("LDAP://rootDSE"
strDefaultDN = objDSE.Get("defaultNamingContext"
strDN = InputBox("Enter the distinguished name of a container" & _
vbCrLf & "(e.g. " & strDefaultDN & "
", , strDefaultDN)
If strDN = "" Then WScript.Quit(1) 'user clicked Cancel
Set objContainer = GetObject("LDAP://" & strDN)
Call ListUsers(objContainer)
Sub ListUsers(objADObject)
Dim objChild
For Each objChild in objADObject
Select Case objChild.Class
Case "user"
res.Writeline objChild.Name & vbTab & _
objChild.Get("distinguishedName"
Case "organizationalUnit" , "container"
Call ListUsers(objChild)
End select
Next
End Sub
---- End Code Paste ----
Does anyone know how i can parse this information? the code is pasted below. I modified it slightly from some sample scripts i have. Thanks for the help.
----Begin Code Paste----
Option Explicit
Dim objDSE, strDefaultDN, strDN, objContainer, objChild
Dim fs, res
Set fs = WScript.CreateObject("Scripting.FileSystemObject"
Set res = fs.CreateTextFile("c:\Users.txt", True)
res.Writeline ("Users details"
Set objDSE = GetObject("LDAP://rootDSE"
strDefaultDN = objDSE.Get("defaultNamingContext"
strDN = InputBox("Enter the distinguished name of a container" & _
vbCrLf & "(e.g. " & strDefaultDN & "
If strDN = "" Then WScript.Quit(1) 'user clicked Cancel
Set objContainer = GetObject("LDAP://" & strDN)
Call ListUsers(objContainer)
Sub ListUsers(objADObject)
Dim objChild
For Each objChild in objADObject
Select Case objChild.Class
Case "user"
res.Writeline objChild.Name & vbTab & _
objChild.Get("distinguishedName"
Case "organizationalUnit" , "container"
Call ListUsers(objChild)
End select
Next
End Sub
---- End Code Paste ----