PropertyCache (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 variables
'**********************************************************************
Dim objGroup 'The group whose property list you want to investigate
Dim strText 'A text string that displays results in one message box
Dim intPropCount 'The number of properties
Dim intIndex 'The index used while looping through the property list
Dim objPropEntry 'An individual property entry used in a loop
Set objGroup = GetObject("LDAP://cn=Managers,ou=Sales,dc=mycorp,dc=com")
objGroup.GetInfo
intPropCount = objGroup.PropertyCount
WScript.Echo "There are " & intPropCount & " values in the property cache."
'**********************************************************************
'Approach 1: PropertyCount property method
'**********************************************************************
strText = ""
For intIndex = 0 To (intPropCount-1)
strText = strText & objGroup.Item(intIndex).Name & vbTab _
& objGroup.Item(intIndex).ADsType & vbCrLf
Next
WScript.Echo strText
'**********************************************************************
'Approach 2: Next method
'**********************************************************************
strText = ""
Set objPropEntry = objGroup.Next
While (Not (IsNull(objPropEntry)) And Err.Number = 0)
strText = strText & objPropEntry.Name & vbTab & objPropEntry.ADsType
& vbCrLf
Set objPropEntry = objGroup.Next
Wend
WScript.Echo strText
Set objPropEntry = Nothing
'**********************************************************************
'Approach 3: Next and Skip methods
'**********************************************************************
strText = ""
objGroup.Reset
Set objPropEntry = objGroup.Next
While (Not (IsNull(objPropEntry)) And Err.Number = 0)
strText = strText & objPropEntry.Name & vbTab & objPropEntry.ADsType
& vbCrLf
objGroup.Skip(2)
Set objPropEntry = objGroup.Next
Wend
WScript.Echo strText
Set objPropEntry = Nothing
|
This code has been viewed 1243 times.
|
New from the creators of TechTasks.com:
StatSheet.com
|