List All User Object Attributes in Active Directory Schema.. Whew!

Here is a lit­tle script I put togeth­er for one of our devel­op­ers here at Aero­jet. Feel free to use, abuse, change, tweak, fix, etc.

Here is a zip file of the script: list-all-attributes.zip

'*  Script name:   List All Attributes.vbs
'*  Created on:    01/28/2009
'*  Author:        Andrew J Healey
'*  Purpose:       Exports all attributes from the user object type within
'*                 the Active Directory schema.
'*  Usage:         cscript /nologo "list all attributes.vbs" > Attributes.csv
'*  History:       Andrew J Healey 01/28/2009
'*                  - Created script
'
Option Explicit

'Declarations
Dim objUserClass : Set objUserClass = GetObject("LDAP://schema/user")
Dim objSchemaClass : Set objSchemaClass = GetObject(objUserClass.Parent)

wscript.echo chr(34) & "Mandatory" & chr(34) & "," & _
			 chr(34) & "Name" & chr(34) & "," & _
			 chr(34) & "Syntax" & chr(34) & "," & _
			 chr(34) & "Single/Multi Valued" & chr(34)

Call GetAttributes(objUserClass.MandatoryProperties,objSchemaClass,True)
Call GetAttributes(objUserClass.OptionalProperties,objSchemaClass,False)

Private Sub GetAttributes(x,y,z)
	Dim strAttribute
	
	'Loop through all attributes
	For Each strAttribute in x
		Dim strOut : strOut = ""

		'Compares whether the attribute is mandatory or optional
		'Prints whether mandatory/optional and name of attribute
		If z = True then
			strOut = strOut & chr(34) & "Yes" & chr(34) & "," & _
							  chr(34) & strAttribute & chr(34) & ","
		Else
			strOut = strOut & chr(34) & "No" & chr(34) & "," & _
							  chr(34) & strAttribute & chr(34) & ","
		End If

		'Get the attributes syntax: i.e. Integer, String, NumericString, etc.
		Dim objAttribute : Set objAttribute = y.GetObject("Property",  strAttribute)
		strOut = strOut & chr(34) & objAttribute.Syntax & chr(34) & ","

		'Determines whether column holds multi or single values
		If objAttribute.MultiValued Then
			strOut = strOut & chr(34) & "Multi" & chr(34)
		Else
			strOut = strOut & chr(34) & "Single" & chr(34)
		End If
		
		'Print string to screen. Each line its own CSV.
		wscript.echo strOut
		strOut = Empty
	Next
	Set objAttribute = Nothing
	strAttribute = Empty
End Sub

15 comments

  1. You probal­ly already know this but
    by adding a few lines you can ouput this to a file:

    * Script name: List All Attributes.vbs
    ‘* Cre­at­ed on: 01/28/2009
    ‘* Author: Andrew J Healey
    ‘* Pur­pose: Exports all attrib­ut­es from the user object type with­in
    ‘* the Active Direc­to­ry schema.
    ‘* Usage: cscript /nologo “list all attributes.vbs” > Attributes.csv
    ‘* His­to­ry: Andrew J Healey 01/28/2009
    ‘* - Cre­at­ed script

    ’ ****** add code *********

    Set WSHShell = CreateObject(“WScript.Shell”)
    Set objF­SO = CreateObject(“Scripting.FileSystemObject”)
    obj­path = WshShell.SpecialFolders(“Desktop”)
    Set obj­Fold­er = objFSO.GetFolder(objpath)
    For Each obj­File In objFolder.files
    If objFile.Name = “users.txt” Then
    objFile.Delete True
    End If
    Next
    Set obj­file = objFSO.CreateTextFile(objpath&“ad.csv”, True)
    set obj­file = noth­ing
    Set obj­file = objFSO.OpenTextFile(objpath&“ad.csv”, 8, True)

    ’ ****** end add *********

    Dim objUser­Class : Set objUser­Class = GetObject(“LDAP://schema/user”)
    Dim objSchemaClass : Set objSchemaClass = GetObject(objUserClass.Parent)

    ’ ****** change code - from *********

    wscript.echo chr(34) & “Manda­to­ry” & chr(34) & “,” & _
    ’ chr(34) & “Name” & chr(34) & “,” & _
    ’ chr(34) & “Syn­tax” & chr(34) & “,” & _
    ’ chr(34) & “Single/Multi Val­ued” & chr(34)

    ’ ****** change code - to *********

    writeme = chr(34) & “Manda­to­ry” & chr(34) & “,” & chr(34) & “Name” & chr(34) & “,” & chr(34) & “Syn­tax” & chr(34) & “,” & chr(34) & “Single/Multi Val­ued” & chr(34)
    objfile.writeline(writeme)

    ’ ****** end change code *********

    Call GetAttributes(objUserClass.MandatoryProperties,objSchemaClass,True)
    Call GetAttributes(objUserClass.OptionalProperties,objSchemaClass,False)
    Pri­vate Sub GetAttributes(x,y,z)
    Dim strAt­tribute
    For Each strAt­tribute in x
    Dim strOut : strOut = “”
    If z = True then
    strOut = strOut & chr(34) & “Yes” & chr(34) & “,” & chr(34) & strAt­tribute & chr(34) & “,”
    Else
    strOut = strOut & chr(34) & “No” & chr(34) & “,” & chr(34) & strAt­tribute & chr(34) & “,”
    End If
    Dim objAt­tribute : Set objAt­tribute = y.GetObject(“Property”, strAt­tribute)
    strOut = strOut & chr(34) & objAttribute.Syntax & chr(34) & “,”
    If objAttribute.MultiValued Then
    strOut = strOut & chr(34) & “Mul­ti” & chr(34)
    Else
    strOut = strOut & chr(34) & “Sin­gle” & chr(34)
    End If

    ’ ****** change code - from *********

    ’ wscript.echo strOut

    ’ ****** change code - to *********

    objfile.writeline(strOut)

    ’ ****** end sec­tion *********

    strOut = Emp­ty
    Next
    Set objAt­tribute = Noth­ing
    strAt­tribute = Emp­ty
    End Sub

    ’ ****** add code *********
    Set obj­Do­main = Noth­ing
    objfile.close
    set obj­file = noth­ing
    set objf­so = noth­ing
    Wscript.Echo “AD file cre­at­ed, DONE
    ’ ****** end add *********

  2. I ran the script and got an com­pi­la­tion error, “Sub expect­ed”. I ran it on a domain com­put­er with an admin­is­tra­tive user account. Is this sup­posed to be run from the Domain Con­troller itself?

  3. Hi!

    How can I add fields in the Attrib­ut­es Edi­tor: attribute = extensionAttribute5 Share­pointO­BS to all user accounts that have not

  4. Just found your script and it was real­ly use­ful. I added a small tweak to suit my need of see­ing the OID. Just had to add a line to print out the OID col­umn head­er in the first echo state­ment.
    -----------------
    chr(34) &OID& chr(34) & “,” & _
    -----------------
    and then in the GetAt­trib­ut­es function/method after print­ing the Syn­tax por­tion
    -----------------
    strOut = strOut & chr(34) & objAttribute.Oid & chr(34) & “,”
    -----------------

    We need OID for doing some attribute map­ping on a Shib­bo­leth instance at our Uni­ver­si­ty. Great script!

  5. This is exact­ly what I’m look­ing for! I am hav­ing an issue export­ing to a file though. I copied and past­ed ‘mikep’ code to out­put it to a file and I get an com­pile error. Can some­one please show me what I need to tweak to export this to a file?

  6. I tried to used the script for a user in AD,
    but i get the error that the manda­to­ryprop­er­ties does­nt works with my user­ac­count

    Dim objUser­Class : Set objUser­Class = GetObject(“LDAP://CN=testUser,OU=OU-Admin,OU=Users,DC=Test,DC=LOCAL”)”

    maybe there is my issue?

  7. Thanks for the script just what I need­ed. Save the VBS script and run the fol­low­ing com­mand from pow­er­shell to export the results to file.
    cscript YOUR.VBS >output.txt

Comments are closed.