Here is a little script I put together for one of our developers here at Aerojet. 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
Thanks for the script!
There’s a typo in the file name in the Usage section though 🙂
Most impressive! Thanks mate.
works well, thanks!
A great help and works well! Thanks much!
You probally already know this but
by adding a few lines you can ouput this to a file:
‘* 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
‘
‘ ****** add code *********
Set WSHShell = CreateObject(“WScript.Shell”)
Set objFSO = CreateObject(“Scripting.FileSystemObject”)
objpath = WshShell.SpecialFolders(“Desktop”)
Set objFolder = objFSO.GetFolder(objpath)
For Each objFile In objFolder.files
If objFile.Name = “users.txt” Then
objFile.Delete True
End If
Next
Set objfile = objFSO.CreateTextFile(objpath&”ad.csv”, True)
set objfile = nothing
Set objfile = objFSO.OpenTextFile(objpath&”ad.csv”, 8, True)
‘ ****** end add *********
Dim objUserClass : Set objUserClass = GetObject(“LDAP://schema/user”)
Dim objSchemaClass : Set objSchemaClass = GetObject(objUserClass.Parent)
‘ ****** change code – from *********
‘wscript.echo chr(34) & “Mandatory” & chr(34) & “,” & _
‘ chr(34) & “Name” & chr(34) & “,” & _
‘ chr(34) & “Syntax” & chr(34) & “,” & _
‘ chr(34) & “Single/Multi Valued” & chr(34)
‘ ****** change code – to *********
writeme = chr(34) & “Mandatory” & chr(34) & “,” & chr(34) & “Name” & chr(34) & “,” & chr(34) & “Syntax” & chr(34) & “,” & chr(34) & “Single/Multi Valued” & chr(34)
objfile.writeline(writeme)
‘ ****** end change code *********
Call GetAttributes(objUserClass.MandatoryProperties,objSchemaClass,True)
Call GetAttributes(objUserClass.OptionalProperties,objSchemaClass,False)
Private Sub GetAttributes(x,y,z)
Dim strAttribute
For Each strAttribute in x
Dim strOut : strOut = “”
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
Dim objAttribute : Set objAttribute = y.GetObject(“Property”, strAttribute)
strOut = strOut & chr(34) & objAttribute.Syntax & chr(34) & “,”
If objAttribute.MultiValued Then
strOut = strOut & chr(34) & “Multi” & chr(34)
Else
strOut = strOut & chr(34) & “Single” & chr(34)
End If
‘ ****** change code – from *********
‘ wscript.echo strOut
‘ ****** change code – to *********
objfile.writeline(strOut)
‘ ****** end section *********
strOut = Empty
Next
Set objAttribute = Nothing
strAttribute = Empty
End Sub
‘ ****** add code *********
Set objDomain = Nothing
objfile.close
set objfile = nothing
set objfso = nothing
Wscript.Echo “AD file created, DONE”
‘ ****** end add *********
And by the way GREAT SCRIPT, THANK YOU !!!
Thanks Mike. Glad you found it useful.
For these, I typically just use: cscript /nologo script.vbs > output.csv
I ran the script and got an compilation error, “Sub expected”. I ran it on a domain computer with an administrative user account. Is this supposed to be run from the Domain Controller itself?
Hi!
How can I add fields in the Attributes Editor: attribute = extensionAttribute5 SharepointOBS to all user accounts that have not
Just found your script and it was really useful. I added a small tweak to suit my need of seeing the OID. Just had to add a line to print out the OID column header in the first echo statement.
—————–
chr(34) & “OID” & chr(34) & “,” & _
—————–
and then in the GetAttributes function/method after printing the Syntax portion
—————–
strOut = strOut & chr(34) & objAttribute.Oid & chr(34) & “,”
—————–
We need OID for doing some attribute mapping on a Shibboleth instance at our University. Great script!
This is exactly what I’m looking for! I am having an issue exporting to a file though. I copied and pasted ‘mikep’ code to output it to a file and I get an compile error. Can someone please show me what I need to tweak to export this to a file?
I tried to used the script for a user in AD,
but i get the error that the mandatoryproperties doesnt works with my useraccount
“Dim objUserClass : Set objUserClass = GetObject(“LDAP://CN=testUser,OU=OU-Admin,OU=Users,DC=Test,DC=LOCAL”)”
maybe there is my issue?
Thanks mate.. That was really useful..
Thanks for the script just what I needed. Save the VBS script and run the following command from powershell to export the results to file.
cscript YOUR.VBS >output.txt