' From the book "Active Directory, Third Edition"
' ISBN: 0-596-10173-2
Option Explicit
On Error Resume Next
'**********************************************************************
'Declare the hash (dictionary), constants and variables
'**********************************************************************
Dim dicADsType
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"
Const ADS_PROPERTY_CLEAR = 1
Const ADS_PROPERTY_UPDATE = 2
Const ADS_PROPERTY_APPEND = 3
Const ADS_PROPERTY_DELETE = 4
Dim objPropValue 'An individual property value within a loop
Dim objPropEntry 'An ADSI PropertyEntry object
Dim objObject 'The object whose property list we wish to investigate
Dim strText 'A text string used to display results in one go
Dim intPropCount 'The number of properties in
Dim intIndex 'The index used while looping through the property list
Dim intCount 'Used to display property values in a numbered sequence
'**********************************************************************
'Uncomment one of these lines and modify it to your own environment.
'The first uses the LDAP namespace; the second uses the WinNT namespace.
'**********************************************************************
' Set objObject = GetObject("LDAP://cn=administrator,cn=users,dc=mycorp,dc=com")
' Set objObject = GetObject("WinNT://WINDOWS/Managers,Group")
objObject.GetInfo
if (Err.Number > 0) Then
Wscript.Echo "Object not found, returning..."
Wscript.Quit
End if
'**********************************************************************
'Write out the current property cache total to the string that is
'storing output
'**********************************************************************
intPropCount = objObject.PropertyCount
strText = "There are " & intPropCount & _
" values in the property cache." & vbCrLf
'**********************************************************************
'The extra vbTabs used in the first loop are to space the results so
'that they are nicely formatted with the list of values in the second loop
'**********************************************************************
For intIndex = 0 To (intPropCount-1)
Set objPropEntry = objObject.Item(intIndex)
strText = strText & objPropEntry.Name & vbCrLf
strText = strText & vbTab & "Type:" & vbTab & vbTab & _
dicADsType.Item(objPropEntry.ADsType) & vbCrLf
'**********************************************************************
'Go through each property value in the property entry and use the AdsType
'to print out the appropriate value, prefixed by a count (intCount), i.e.:
'
' Value #1: Vicky Launders
' Value #2: Alistair Lowe-Norris
' Value #3: Robbie Allen
'**********************************************************************
intCount = 1
For Each objPropValue In objPropEntry.Values
If (dicADsType(objPropValue.ADsType) = "STRING") Then
strText = strText & vbTab & "Value #" & intCount & ":" _
& vbTab & objPropValue.DNString & vbCrLf
ElseIf (dicADsType(objPropValue.ADsType) = "CASE_EXACT_STRING") Then
strText = strText & vbTab & "Value #" & intCount & ":" _
& vbTab & objPropValue.CaseExactString & vbCrLf
ElseIf (dicADsType(objPropValue.ADsType) = "CASE_IGNORE_STRING") Then
strText = strText & vbTab & "Value #" & intCount & ":" _
& vbTab & objPropValue.CaseIgnoreString & vbCrLf
ElseIf (dicADsType(objPropValue.ADsType) = "PRINTABLE_STRING") Then
strText = strText & vbTab & "Value #" & intCount & ":" _
& vbTab & objPropValue.PrintableString & vbCrLf
ElseIf (dicADsType(objPropValue.ADsType) = "NUMERIC_STRING") Then
strText = strText & vbTab & "Value #" & intCount & ":" _
& vbTab & objPropValue.NumericString & vbCrLf
ElseIf (dicADsType(objPropValue.ADsType) = "BOOLEAN") Then
strText = strText & vbTab & "Value #" & intCount & ":" _
& vbTab & CStr(objPropValue.Boolean) & vbCrLf
ElseIf (dicADsType(objPropValue.ADsType) = "INTEGER") Then
strText = strText & vbTab & "Value #" & intCount & ":" _
& vbTab & objPropValue.Integer & vbCrLf
End If
intCount=intCount+1
Next
Next
WScript.Echo strText
|