Walk PropertyCache with Schema (VBScript)
This code can be found in
Chapter 21 of Active Directory, 3rd 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.
' From the book "Active Directory, Third Edition"
' ISBN: 0-596-10173-2
Option Explicit
'**********************************************************************
'Force error checking within the code using the Err.Number property
'method in approaches 2 and 3
'**********************************************************************
On Error Resume Next
'**********************************************************************
'Declare the constants and variables
'**********************************************************************
Dim objObject 'Active Directory object
Dim objClass 'ADSI Class object
Dim objProp 'An individual property
Dim intCount 'Incremental counter for display
Dim fileadsect 'A FileSystemObject
Dim outTextFile 'A TextStream Object
'**********************************************************************
'Create a VBScript file object and use it to open a text file. The
'second parameter specifies to overwrite any existing file that exists.
'**********************************************************************
Set fileadsect = CreateObject("Scripting.FileSystemObject")
Set outTextFile = fileadsect.CreateTextFile("c:\out.txt", TRUE)
'**********************************************************************
'Bind to the object and get a pointer to the appropriate schema class,
'i.e., User in this case
'**********************************************************************
Set objObject =
GetObject("LDAP://cn=administrator,cn=Users,dc=mycorp,dc=com")
Set objClass = GetObject(objObject.Schema)
intCount = 1
'**********************************************************************
'Iterate through all the mandatory properties
'**********************************************************************
For Each objProp in objClass.MandatoryProperties
EnumerateProperties objProp, outTextFile, objObject
intCount=intCount+1
Next
'**********************************************************************
'Iterate through all the optional properties
'**********************************************************************
For Each objProp in objClass.OptionalProperties
EnumerateProperties objProp
intCount=intCount+1
Next
outTextFile.Close
'**********************************************************************
'Subroutine EnumerateProperties
'**********************************************************************
Sub EnumerateProperties(ByVal objProp, ByVal tsFile, ByVal objObj)
Dim objProperty 'ADSI Property object
Dim arrElement 'Array of elements
'**********************************************************************
'Get pointer to the schema property object
'**********************************************************************
Set objProperty = GetObject("LDAP://Schema/" & objProp)
'**********************************************************************
'Check whether property requires GetEx using IADsProperty::MultiValued
'**********************************************************************
If objProperty.MultiValued Then
tsFile.WriteLine intCount & ") " & objProp & _
" (" & objProperty.Syntax & ") (MULTI-VALUED)"
'**********************************************************************
'Check whether array returned from GetEx is empty using VBScript
function
'**********************************************************************
If (IsEmpty(objObj.GetEx(objProp))) Then
tsFile.WriteLine vbTab & "= " & "NO VALUES SET!"
Else
For Each arrElement in objObj.GetEx(objProp)
tsFile.WriteLine vbTab & "= " & arrElement
Next
End If
Else
tsFile.WriteLine intCount & ") " & objProp _
& " (" & objProperty.Syntax & ")"
Err.Clear
If Err=0 Then
tsFile.WriteLine vbTab & "= " & objObj.Get(objProp)
Else
tsFile.WriteLine vbTab & "= " & "Not Set!"
End If
End If
End Sub
|
This code has been viewed 1593 times.
|
New from the creators of TechTasks.com:
StatSheet.com
|