Solved

Find out if Active Directory  2003 schema has custom attributes

Posted on 2013-12-23
7
634 Views
Last Modified: 2014-01-12
In preparation of Active Directory Upgrade from Windows 2003 R2 to Windows 2012 R2, I am trying to find if Active Directory schema has any unsupported customizations.
What is the best way to do it?
Thanks!
0
Comment
Question by:IT-NYC
  • 3
7 Comments
 
LVL 10

Expert Comment

by:convergint
Comment Utility
I am not a programmer but this link may help you:

http://ad911.weebly.com/3/post/2011/11/find-custom-attributes-for-all-users-in-active-directory.html

If the link breaks, this is the contents:

Pre-Requisites:
1) Excel should be installed on the machine where this script would be executed
2) All the users in active directory should be dumped to " C:\scripts\Ad stale cleanup project\month1day1\StaleUsers.txt " or modify the source / destination path.
-----------------------------------------------------------
-----------------------------------------------------------
On Error Resume next
Dim aUser,StrUser
Dim objExec,DistName,objUser,objLogon,objtxtFSO,strlog,objBB,BBValue,strlog1,objtxtFile1,objtxtFSO1
Dim objRootDSE,strDomain,objCommand,objRecordSet,objConnection ,CoMN
Const ADS_SCOPE_SUBTREE = 2

Set Fso = CreateObject("Scripting.FileSystemObject")
Set Fso = CreateObject("Scripting.FileSystemObject")


'Create a txt file for stale computers
Dim objtxtFile
strlog= "C:\scripts\Ad stale cleanup project\month1day1\StaleUsers.txt"
Set objtxtFSO=CreateObject("Scripting.Filesystemobject")
Set objtxtFile=objtxtFSO.CreateTextFile(strlog,True)
 
 
If FSO.FileExists("C:\scripts\Ad stale cleanup project\month1day1\CustomAttr.xlsx") Then
    fso.DeleteFile "C:\scripts\Ad stale cleanup project\month1day1\CustomAttr.xlsx"
End If

Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = False
Set objWorkbook = objExcel.Workbooks.Add()
Set objWorksheet = objWorkbook.Worksheets(1)
intRow = 2


objExcel.Cells(1, 1).Value = "Display Name"
objExcel.Cells(1, 2).Value = "extensionAttribute1"
objExcel.Cells(1, 3).Value = "extensionAttribute2"
objExcel.Cells(1, 4).Value = "extensionAttribute3"
objExcel.Cells(1, 5).Value = "extensionAttribute4"
objExcel.Cells(1, 6).Value = "extensionAttribute5"
objExcel.Cells(1, 7).Value = "extensionAttribute6"
objExcel.Cells(1, 8).Value = "extensionAttribute7"
objExcel.Cells(1, 9).Value = "extensionAttribute8"
objExcel.Cells(1, 10).Value = "extensionAttribute9"
objExcel.Cells(1, 11).Value = "extensionAttribute10"
objExcel.Cells(1, 12).Value = "extensionAttribute11"
objExcel.Cells(1, 13).Value = "extensionAttribute12"
objExcel.Cells(1, 14).Value = "extensionAttribute13"
objExcel.Cells(1, 15).Value = "extensionAttribute14"
objExcel.Cells(1, 16).Value = "extensionAttribute15"
objExcel.Cells(1, 2).Interior.ColorIndex = 27
objExcel.Cells(1, 5).Interior.ColorIndex = 27
objExcel.Cells(1, 6).Interior.ColorIndex = 27
objExcel.Cells(1, 1).Interior.ColorIndex = 27
objExcel.Cells(1, 7).Interior.ColorIndex = 27
objExcel.Cells(1, 8).Interior.ColorIndex = 27
objExcel.Cells(1, 3).Interior.ColorIndex = 27
objExcel.Cells(1, 4).Interior.ColorIndex = 27
objExcel.Cells(1, 9).Interior.ColorIndex = 27
objExcel.Cells(1, 10).Interior.ColorIndex = 27
objExcel.Cells(1, 11).Interior.ColorIndex = 27
objExcel.Cells(1, 12).Interior.ColorIndex = 27
objExcel.Cells(1, 13).Interior.ColorIndex = 27
objExcel.Cells(1, 14).Interior.ColorIndex = 27
objExcel.Cells(1, 15).Interior.ColorIndex = 27
objExcel.Cells(1, 16).Interior.ColorIndex = 27
objExcel.Cells(1, 2).font.bold = True
objExcel.Cells(1, 5).font.bold = True
objExcel.Cells(1, 6).font.bold = True
objExcel.Cells(1, 1).font.bold = True
objExcel.Cells(1, 7).font.bold = True
objExcel.Cells(1, 8).font.bold = True
objExcel.Cells(1, 3).font.bold = True
objExcel.Cells(1, 4).font.bold = True
objExcel.Cells(1, 9).font.bold = True
objExcel.Cells(1, 10).font.bold = True
objExcel.Cells(1, 11).font.bold = True
objExcel.Cells(1, 12).font.bold = True
objExcel.Cells(1, 13).font.bold = True
objExcel.Cells(1, 14).font.bold = True
objExcel.Cells(1, 15).font.bold = True
objExcel.Cells(1, 16).font.bold = True
objexcel.Selection.Autofilter
 
Set oFS = CreateObject("Scripting.FileSystemObject")
Set objShell = CreateObject("WScript.Shell")
InputFile = "C:\scripts\Ad stale cleanup project\month1day1\AllUsers.txt"
Set f = oFS.OpenTextFile(InputFile)
 
StrUser = f.ReadAll
f.Close
arrUsers = Split(StrUser,vbCrLf)
 
For Each aUser in arrUsers

Set objRootDSE = GetObject("LDAP://RootDSE")
strDomain = objRootDSE.Get("DefaultNamingContext")

' Set ADO connection
Set objConnection = CreateObject("ADODB.Connection")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"

' Set ADO command
Set objCommand = CreateObject("ADODB.Command")
Set objCommand.ActiveConnection = objConnection
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
objCommand.CommandText = "SELECT distinguishedName FROM 'LDAP://" & strDomain & "' WHERE objectCategory='user' AND samAccountName = '" & auser & "'"

' Set recordset to hold the query result
Set objRecordSet = objCommand.Execute
DistName = objRecordSet.Fields("distinguishedName").Value

If DistName <> "" then

'If distinguished Name is a null value ( null value for deleted users ) then such users are not processed.

set objUser = GetObject("LDAP://" & DistName)
 
set objLogon = objUser.Get("lastLogontimestamp")

ext1 = objUser.Get("extensionAttribute1")
ext2 = objUser.Get("extensionAttribute2")
ext3 = objUser.Get("extensionAttribute3")
ext4 = objUser.Get("extensionAttribute4")
ext5 = objUser.Get("extensionAttribute5")
ext6 = objUser.Get("extensionAttribute6")
ext7 = objUser.Get("extensionAttribute7")
ext8 = objUser.Get("extensionAttribute8")
ext9 = objUser.Get("extensionAttribute9")
ext10 = objUser.Get("extensionAttribute10")
ext11 = objUser.Get("extensionAttribute11")
ext12 = objUser.Get("extensionAttribute12")
ext13 = objUser.Get("extensionAttribute13")
ext14 = objUser.Get("extensionAttribute14")
ext15 = objUser.Get("extensionAttribute15")
CoMN = objUser.Get("cn")


objExcel.Cells(intRow, 2).Value = ext1
objExcel.Cells(intRow, 5).Value = ext4
objExcel.Cells(intRow, 6).Value = ext5
objExcel.Cells(intRow, 1).Value = CoMN
objExcel.Cells(intRow, 7).Value = ext6
objExcel.Cells(intRow, 8).Value = ext7
objExcel.Cells(intRow, 3).Value = ext2
objExcel.Cells(intRow, 4).Value = ext3
objExcel.Cells(intRow, 9).Value = ext8
objExcel.Cells(intRow, 10).Value = ext9
objExcel.Cells(intRow, 11).Value = ext10
objExcel.Cells(intRow, 12).Value = ext11
objExcel.Cells(intRow, 13).Value = ext12
objExcel.Cells(intRow, 14).Value = ext13
objExcel.Cells(intRow, 15).Value = ext14
objExcel.Cells(intRow, 16).Value = ext15



intRow = intRow + 1
End If

objBB = Null
objBBC = Null
div = Null
aUser = Null
Country = Null
DistName = Null
StaleDate = Null
CoMN = Null

Next

objexcel.Cells.EntireColumn.AutoFit
objexcel.Cells.EntireRow.AutoFit
objWorkbook.SaveAs "C:\scripts\Ad stale cleanup project\month1day1\CustomAttr.xlsx"
objExcel.Quit
MsgBox "Script Executed. Please check the output."
0
 

Author Comment

by:IT-NYC
Comment Utility
Get error when trying to run it.
Posted to a question to the author (see below)

Experts,
Any other ideas?

------------------------------------------------
I am trying to run your script on Windows 7 machine against Windows 2003 R2 forest. This is the error I get:
 "At line:93 char:3
 + ' Set ADO connection
 + ~~~
 Unexpected token 'Set' in expression or statement.
 At line:102 char:58
 + objCommand.CommandText = "SELECT distinguishedName FROM 'LDAP://" & strDomain & ...
 + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 Unexpected token 'LDAP://" & strDomain & "' WHERE objectCategory='user' AND samAccountName = '" & auser & "'"
 '' in expression or statement.
 At line:108 char:3
 + If DistName <> "" then
 + ~
 Missing '(' after 'If' in if statement.
 At line:108 char:14
 + If DistName <> "" then
 + ~
 Missing file specification after redirection operator.
 At line:108 char:13
 + If DistName <> "" then
 + ~
 The '<' operator is reserved for future use.
 At line:110 char:1
 + 'If distinguished Name is a null value ( null value for deleted users ) then suc ...
 + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 The string is missing the terminator: '.
 + CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException
 + FullyQualifiedErrorId : UnexpectedToken"
 Any advice will be appreciated. Thanks!"
0
 
LVL 70

Expert Comment

by:Chris Dent
Comment Utility
I think we should be able to do it if we look for schema objects which are not part of the base.

This is still going to need some exploration because other systems which add attributes, such as Exchange, may not set this flag (unable to verify at this time). In addition, you may find this flag is not reliably set which will completely scupper this plan.

The following code is in PowerShell, your Windows 7 box will have that by default.
$RootDSE = [ADSI]"LDAP://RootDSE"
$Schema = [ADSI]"LDAP://$($RootDSE.schemaNamingContext)"

$Searcher = [ADSISearcher]"(!(systemFlags:1.2.840.113556.1.4.803:=16))"
$Searcher.PageSize = 1000
$Searcher.SearchRoot = $Schema

$Searcher.FindAll() | ForEach-Object { $_.Properties['name'][0] }}

Open in new window

If that returns nothing, or everything, another method will have to be attempted.

Chris
0
 

Accepted Solution

by:
IT-NYC earned 0 total points
Comment Utility
0
 

Author Closing Comment

by:IT-NYC
Comment Utility
I found the solution myself, posted the solution link
0

Featured Post

Want to promote your upcoming event?

Are you going to an event? Are you going to be exhibiting at a tradeshow? Talking at a conference? Using a promotional banner in your email signature ensures that your organization’s most important contacts stay in the know and can potentially spread the word about the event.

Join & Write a Comment

In this article, we will see the basic design consideration while designing a Multi-tenant web application in a simple manner. Though, many frameworks are available in the market to develop a multi - tenant application, but do they provide data, cod…
ADCs have gained traction within the last decade, largely due to increased demand for legacy load balancing appliances to handle more advanced application delivery requirements and improve application performance.
This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles to another domain controller. Log onto the new domain controller with a user account t…
This tutorial will walk an individual through the process of configuring their Windows Server 2012 domain controller to synchronize its time with a trusted, external resource. Use Google, Bing, or other preferred search engine to locate trusted NTP …

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now