WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

Samples from Users

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

ADSI Get OU Properties


AddExtender("wwads34i.dll")
; samAccountName of user of interest
MyUser = "brendan"  ;CHANGE TO REFLECT WHOS SETTINGS YOU WANT TO SEE
MANDATORY  = 1
OPTIONAL   = 2
MANANDOPT  = 3

ServerDn=dsGetProperty("LDAP://rootDSE", "serverName")
ServerName=ItemExtract(1, ServerDn, ",")
ServerName=ItemExtract(2, ServerName, "=")
ServerDn=dsGetProperty("LDAP://rootDSE", "defaultNamingContext")
ServerPath="LDAP://%ServerName%/%ServerDN%"
UserPath=dsFindPath(ServerPath, "(&(objectCategory=organizationalunit)(ou=*))")

file=FileOpen("c:\ADSI-%MyUser%.txt","WRITE")
; Get mandatory properties of object.
sList = dsGetPropName(UserPath,MANDATORY)
if sList != ""
   count=ItemCount(sList,@TAB)
   FileWrite(file,"Mandatory Property Value(s)")
   for i = 1 to count
      name=ItemExtract(i,sList,@TAB)
      ErrorMode(@OFF)
         props=dsGetProperty(UserPath,name)
      ErrorMode(@CANCEL)
      FileWrite(file,StrCat(name,"|",props))
   next
endif 

FileWrite(file,"")
count=""

; Get optional properties of object.
sList = dsGetPropName(UserPath, OPTIONAL)
if sList != ""
   count=ItemCount(sList,@TAB)
   FileWrite(file,"Optional Property Value(s)")
   for i = 1 to count
      name=ItemExtract(i,sList,@TAB)
      ErrorMode(@OFF)
         props=dsGetProperty(UserPath,name)
      ErrorMode(@CANCEL)
      FileWrite(file,StrCat(name,"|",props))
      next
endif  
FileClose(file)

;the file created is a "|" delimeted file...
;open excel then open the file
;Run("excel.exe", "c:\ADSI-%MyUser%.txt"
)
Article ID:   W15821
File Created: 2004:03:30:15:41:00
Last Updated: 2004:03:30:15:41:00