' DocumentProperties.vbs ' VBScript program to document all properties for a given Active ' Directory object. All properties in the Schema are listed, whether ' assigned a value or not. The values of the properties are output. The ' program requires the full AdsPath to an Active Directory object, using ' either the WinNT provider or the LDAP provider. Each provider exposes ' different properties. ' ' ---------------------------------------------------------------------- ' Copyright (c) 2002-2010 Richard L. Mueller ' Hilltop Lab web site - http://www.rlmueller.net ' Version 1.0 - November 10, 2002 ' Version 1.1 - February 19, 2003 - Standardize Hungarian notation. ' Version 1.2 - May 9, 2003 - Account for error in IADsLargeInteger ' property methods HighPart and LowPart. ' Version 1.3 - January 25, 2004 - Modify error trapping. ' Version 1.4 - February 24, 2004 - Bug fix. ' Version 1.5 - October 13, 2010 - Improve handling of Integer8 and ' Boolean values. ' Version 1.6 - November 6, 2010 - No need to set objects to Nothing. ' ' This script is designed to be run at a command prompt, using the ' Cscript host. The output can be redirected to a text file. For ' example: ' cscript //nologo DocumentProperties.vbs "ADSPATH" > Properties.txt ' ADSPATH can be similar to: ' "WinNT://MyDomain/TestUser,user" ' or ' "LDAP://cn=TestUser,ou=Sales,dc=MyDomain,dc=com" ' ' You have a royalty-free right to use, modify, reproduce, and ' distribute this script file in any way you find useful, provided that ' you agree that the copyright owner above has no warranty, obligations, ' or liability for such use. Option Explicit Dim objADObject, objClass, strProperty, strValue, strAdsPath Dim objShell, lngBiasKey, lngBias, j, strHex, strItem, objDate, dtmDate Dim lngHigh, lngLow, lngValue, dtmValue If (Wscript.Arguments.Count = 0) Then Wscript.Echo "Error, required argument missing." Wscript.Echo "DocumentProperties.vbs" Wscript.Echo "Program to list AD object properties" Wscript.Echo "Syntax:" Wscript.Echo "cscript DocumentProperties.vbs ADSPATH > output.txt" Wscript.Echo "where ADSPATH is the full AdsPath of an AD object." Wscript.Echo "For example, ADSPATH could be:" Wscript.Echo " WinNT://MyDomain/TestUser,user" Wscript.Echo " LDAP://cn=TestUser,ou=Sales,dc=MyDomain,dc=com" Wscript.Quit(1) End If ' Bind to Active Directory object specified. strAdsPath = Wscript.Arguments(0) On Error Resume Next Set objADObject = GetObject(strAdsPath) If (Err.Number <> 0) Then On Error GoTo 0 Wscript.Echo "Object not found in Active Directory" Wscript.Echo strAdsPath Wscript.Quit(1) End If On Error GoTo 0 ' Determine Time Zone bias in local registry. ' This bias changes with Daylight Savings Time. Set objShell = CreateObject("Wscript.Shell") lngBiasKey = objShell.RegRead("HKLM\System\CurrentControlSet\" _ & "Control\TimeZoneInformation\ActiveTimeBias") If (UCase(TypeName(lngBiasKey)) = "LONG") Then lngBias = lngBiasKey ElseIf (UCase(TypeName(lngBiasKey)) = "VARIANT()") Then lngBias = 0 For j = 0 To UBound(lngBiasKey) lngBias = lngBias + (lngBiasKey(j) * 256^j) Next End If Set objClass = GetObject(objADObject.Schema) ' Enumerate mandatory object properties. For Each strProperty In objClass.MandatoryProperties On Error Resume Next strValue = objADObject.Get(strProperty) If (Err.Number = 0) Then On Error GoTo 0 If (TypeName(strValue) = "String") Or (TypeName(strValue) = "Long") _ Or (TypeName(strValue) = "Date") Then Wscript.Echo "(M) " & Left(strProperty & Space(34), 35) & " = " _ & CStr(strValue) ElseIf (TypeName(strValue) = "Byte()") Then strHex = OctetToHexStr(strValue) Wscript.Echo "(M) " & Left(strProperty & Space(34), 35) & " = " _ & CStr(strHex) ElseIf (TypeName(strValue) = "Variant()") Then For Each strItem In strValue On Error Resume Next Wscript.Echo "(M) " & Left(strProperty & Space(34), 35) _ & " = " & CStr(strItem) If (Err.Number <> 0) Then On Error GoTo 0 Wscript.Echo "(M) " & Left(strProperty & Space(34), 35) _ & " = (Value cannot be displayed" End If On Error GoTo 0 Next ElseIf (TypeName(strValue) = "Boolean") Then Wscript.Echo "(M) " & Left(strProperty & Space(34), 35) _ & " = " & CBool(strValue) Else Wscript.Echo "(M) " & Left(strProperty & Space(34), 35) _ & " Type " & TypeName(strValue) End If Else Err.Clear sColl = objADObject.GetEx(strProperty) If (Err.Number = 0) Then For Each strItem In sColl Wscript.Echo "(M) " & Left(strProperty & Space(34), 35) _ & CStr(strItem) If (Err.Number <> 0) Then Wscript.Echo "(M) " & Left(strProperty & Space(34), 35) _ & "(Value cannot be displayed)" End If Next On Error GoTo 0 Else Err.Clear Set objDate = objADObject.Get(strProperty) If (Err.Number = 0) Then lngHigh = objDate.HighPart If (Err.Number = 0) Then lngLow = objDate.LowPart If (lngLow < 0) Then lngHigh = lngHigh + 1 End If lngValue = (lngHigh * (2 ^ 32)) + lngLow If (lngValue > 120000000000000000) Then dtmValue = #1/1/1601# + (lngValue / 600000000 - lngBias) / 1440 On Error Resume Next dtmDate = CDate(dtmValue) If (Err.Number <> 0) Then Wscript.Echo "(M) " & Left(strProperty & Space(34), 35) _ & " = " Else Wscript.Echo "(M) " & Left(strProperty & Space(34), 35) _ & " = " & CStr(dtmDate) End If Else Wscript.Echo "(M) " & Left(strProperty & Space(34), 35) _ & " = " & FormatNumber(lngValue, 0) End If Else Wscript.Echo "(M) " & Left(strProperty & Space(34), 35) _ & " = (Value cannot be displayed)" End If Else On Error GoTo 0 Wscript.Echo "(M) " & strProperty End If On Error GoTo 0 End If End If Next ' Enumerate optional object properties. For Each strProperty In objClass.OptionalProperties On Error Resume Next strValue = objADObject.Get(strProperty) If (Err.Number = 0) Then On Error GoTo 0 If (TypeName(strValue) = "String") Or (TypeName(strValue) = "Long") _ Or (TypeName(strValue) = "Date") Then Wscript.Echo "(O) " & Left(strProperty & Space(34), 35) & " = " _ & CStr(strValue) ElseIf (TypeName(strValue) = "Byte()") Then strHex = OctetToHexStr(strValue) Wscript.Echo "(O) " & Left(strProperty & Space(34), 35) & " = " _ & CStr(strHex) ElseIf (TypeName(strValue) = "Variant()") Then For Each strItem In strValue On Error Resume Next Wscript.Echo "(O) " & Left(strProperty & Space(34), 35) _ & " = " & CStr(strItem) If (Err.Number <> 0) Then On Error GoTo 0 Wscript.Echo "(O) " & Left(strProperty & Space(34), 35) _ & " = (Value cannot be displayed" End If On Error GoTo 0 Next ElseIf (TypeName(strValue) = "Boolean") Then Wscript.Echo "(O) " & Left(strProperty & Space(34), 35) _ & " = " & CBool(strValue) Else Wscript.Echo "(O) " & Left(strProperty & Space(34), 35) _ & " Type " & TypeName(strValue) End If Else Err.Clear sColl = objADObject.GetEx(strProperty) If (Err.Number = 0) Then For Each strItem In sColl Wscript.Echo "(O) " & Left(strProperty & Space(34), 35) _ & CStr(strItem) If (Err.Number <> 0) Then Wscript.Echo "(O) " & Left(strProperty & Space(34), 35) _ & "(Value cannot be displayed)" End If Next On Error GoTo 0 Else Err.Clear Set objDate = objADObject.Get(strProperty) If (Err.Number = 0) Then lngHigh = objDate.HighPart If (Err.Number = 0) Then lngLow = objDate.LowPart If (lngLow < 0) Then lngHigh = lngHigh + 1 End If lngValue = (lngHigh * (2 ^ 32)) + lngLow If (lngValue > 120000000000000000) Then dtmValue = #1/1/1601# + (lngValue / 600000000 - lngBias) / 1440 On Error Resume Next dtmDate = CDate(dtmValue) If (Err.Number <> 0) Then Wscript.Echo "(O) " & Left(strProperty & Space(34), 35) _ & " = " Else Wscript.Echo "(O) " & Left(strProperty & Space(34), 35) _ & " = " & CStr(dtmDate) End If Else Wscript.Echo "(O) " & Left(strProperty & Space(34), 35) _ & " = " & FormatNumber(lngValue, 0) End If Else Wscript.Echo "(O) " & Left(strProperty & Space(34), 35) _ & " = (Value cannot be displayed)" End If Else On Error GoTo 0 Wscript.Echo "(O) " & strProperty End If On Error GoTo 0 End If End If Next Function OctetToHexStr(arrbytOctet) ' Function to convert OctetString (Byte Array) to a hex string. Dim k OctetToHexStr = "" For k = 1 To Lenb(arrbytOctet) OctetToHexStr = OctetToHexStr _ & Right("0" & Hex(Ascb(Midb(arrbytOctet, k, 1))), 2) Next End Function