Count objects (VBScript)

This code can be found in Chapter 4 of Active Directory Cookbook, 2nd edition

Purchase XP Cookbook or Networking Recipes for only $25 plus shipping! While supplies last.

Find out how to download all of the VBScript code from this site.

' This VBScript code prints all attributes for the specified object.

' ---------------------------------------------------------------
' From the book "Active Directory Cookbook" by Robbie Allen
' Publisher: O'Reilly and Associates
' ISBN: 0-596-00466-4
' Book web site: http://rallenhome.com/books/adcookbook/code.html
' ---------------------------------------------------------------

' ------ SCRIPT CONFIGURATION ------
strObjectDN = "<ObjectDN>" ' e.g. cn=jsmith,cn=users,dc=rallencorp,dc=com
' ------ END CONFIGURATION ---------

DisplayAttributes("LDAP://" & strObjectDN)

Function DisplayAttributes( strObjectADsPath ) 

   set objObject = GetObject(strObjectADsPath)
   objObject.GetInfo

   'Declare the hash (dictionary), constants and variables
   'Values taken from ADSTYPEENUM
   set dicADsType = CreateObject("Scripting.Dictionary")
   dicADsType.Add 0, "INVALID"
   dicADsType.Add 1, "DN_STRING"
   dicADsType.Add 2, "CASE_EXACT_STRING"
   dicADsType.Add 3, "CASE_IGNORE_STRING"
   dicADsType.Add 4, "PRINTABLE_STRING"
   dicADsType.Add 5, "NUMERIC_STRING"
   dicADsType.Add 6, "BOOLEAN"
   dicADsType.Add 7, "INTEGER"
   dicADsType.Add 8, "OCTET_STRING"
   dicADsType.Add 9, "UTC_TIME"
   dicADsType.Add 10, "LARGE_INTEGER"
   dicADsType.Add 11, "PROV_SPECIFIC"
   dicADsType.Add 12, "OBJECT_CLASS"
   dicADsType.Add 13, "CASEIGNORE_LIST"
   dicADsType.Add 14, "OCTET_LIST"
   dicADsType.Add 15, "PATH"
   dicADsType.Add 16, "POSTALADDRESS"
   dicADsType.Add 17, "TIMESTAMP"
   dicADsType.Add 18, "BACKLINK"
   dicADsType.Add 19, "TYPEDNAME"
   dicADsType.Add 20, "HOLD"
   dicADsType.Add 21, "NETADDRESS"
   dicADsType.Add 22, "REPLICAPOINTER"
   dicADsType.Add 23, "FAXNUMBER"
   dicADsType.Add 24, "EMAIL"
   dicADsType.Add 25, "NT_SECURITY_DESCRIPTOR"
   dicADsType.Add 26, "UNKNOWN"
   dicADsType.Add 27, "DN_WITH_BINARY"
   dicADsType.Add 28, "DN_WITH_STRING"

   for intIndex = 0 To (objObject.PropertyCount - 1)
      set objPropEntry = objObject.Item(intIndex)
      for Each objPropValue In objPropEntry.Values  
         value = ""  

         if (dicADsType(objPropValue.ADsType) = "DN_STRING") then
            value = objPropValue.DNString

         elseIf (dicADsType(objPropValue.ADsType) = "CASE_EXACT_STRING") then
            value = objPropValue.CaseExactString

         elseIf (dicADsType(objPropValue.ADsType) = "CASE_IGNORE_STRING") then
            value = objPropValue.CaseIgnoreString

         elseIf (dicADsType(objPropValue.ADsType) = "PRINTABLE_STRING") then
            value = objPropValue.PrintableString

         elseIf (dicADsType(objPropValue.ADsType) = "NUMERIC_STRING") then
            value = objPropValue.NumericString

         elseIf (dicADsType(objPropValue.ADsType) = "BOOLEAN") then
            value = CStr(objPropValue.Boolean)

         elseIf (dicADsType(objPropValue.ADsType) = "INTEGER") then
            value = objPropValue.Integer

         elseIf (dicADsType(objPropValue.ADsType) = "LARGE_INTEGER") then
            set objLargeInt = objPropValue.LargeInteger
            value = objLargeInt.HighPart * 2^32 + objLargeInt.LowPart

         elseIf (dicADsType(objPropValue.ADsType) = "UTC_TIME") then
            value = objPropValue.UTCTime

         else
            value = "<" & dicADsType.Item(objPropEntry.ADsType) & ">"

         end if
         WScript.Echo objPropEntry.Name & " : " & value
      next
   next
End Function

This code has been viewed 4227 times.

New from the creators of TechTasks.com: StatSheet.com