Solved

How can i check each users Direct reportees if they have both Ntlogin & Contact added to them. (Active directory)

Posted on 2008-10-31
18
275 Views
Last Modified: 2010-04-16
Hi,

How can i check each users Direct reportees if they have both Ntlogin & Contact added to them.
In many users i could see the Ntlogin and Contact both have added and they show duplicates. Is there any way i can scan all users in an OU and find the Users who have reportees with the same names with contacts and users accounts.

Regards
Sharath
0
Comment
Question by:bsharath
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 9
  • 9
18 Comments
 
LVL 58

Expert Comment

by:tigermatt
ID: 22869369

How's this? Program in your OU at the top where the Managers are found. Then this script goes and scans all the users, checks direct reportees, and if one direct reportee has the same name, it will throw an error.

Run at a cscript prompt so you can catch the output.

-Matthew

' Set OU where the *Managers* can be found, below
strOUPath = "OU=Advanced Level,OU=Finance Officers,OU=Management,OU=Departments,OU=Internal Users,OU=Users,OU=,DC=company,DC=internal"
 
Set objOU = GetObject("LDAP://" & strOUPath)
 
Dim objReports()
 
For Each objUser in objOU
	
	intArrMax = 0
 
	If TypeName(objUser.directReports) = "Variant()" Then
		
		
		For Each strValue In objUser.directReports
			
			Set objReport = GetObject("LDAP://" & strValue)
			lookupname = objReport.givenName & " " & objReport.sn
			
			For Each x In objReports
				If x = lookupname Then
					WScript.Echo "Direct Report: " & lookupname & " (Manager: " & objUser.cn & ") duplicated!"
				End If
			Next
			redim preserve objReports(intArrMax)
			objreports(intArrMax) = lookupname
			intArrMax = intArrMax + 1
			Set objReport = Nothing
			lookupname = ""
		Next
		
	End If
	
	redim objReports(0)
	
 
Next

Open in new window

0
 
LVL 11

Author Comment

by:bsharath
ID: 22869393
Thank U shall check and get back...
0
 
LVL 11

Author Comment

by:bsharath
ID: 22911861
The script runs but no results...

I have a user who has the same names user and contact in the managers. But the script does not detect
0
How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

 
LVL 58

Expert Comment

by:tigermatt
ID: 22911918

Well it did work, but now doesn't :-(

Will work on and get back.
0
 
LVL 58

Expert Comment

by:tigermatt
ID: 22911934

Ok, I've just rewritten it from scratch. The main points to consider are:

*Ensure you run it from the command prompt using cscript, as it uses WScript.Echo to give the output. If you just double-click the VBS you will not see any output (this is expected).

*Objects in Active Directory CANNOT have the same Full Name. It must be unique. Thus, the only way I have been able to compare whether a User and Contact are the same user are based on their First Name and Surname. The First Name and Surname fields must match between the user and computer accounts for a duplicate to be detected. Let me know if you want me to use Display Name, or some other field to compare, instead.

-Matthew
' Set OU where the *Managers* can be found, below
strOUPath = "OU=Standard Users,OU=Users,OU=GJB,DC=GJB,DC=Bawden"
 
Set objOU = GetObject("LDAP://" & strOUPath)
 
Dim objReports()
 
For Each objUser in objOU
        
        intArrMax = 0
 
        If (TypeName(objUser.directReports) = "Variant()") Then
		
		WScript.Echo "Processing " & objUser.givenName & " " & objUser.sn & " for duplicated Direct Reports"
		
		For Each strValue in objUser.directReports
			
			' Fetch object for this direct report
			Set objReportee = GetObject("LDAP://" & strValue)
			
			lookupname = objReportee.givenName & " " & objReportee.sn
			
			' Loop through the list of users we've already seen to see if this one is duplicated
			For Each strAlreadyProcessed In objReports
				
				If (LCase(strAlreadyProcessed) = LCase(lookupname)) Then
					
					' Duplicate detected
					WScript.Echo "** Duplicate Detected: " & lookupname & " (Manager: " & objUser.cn & ") **"
				
				End If
				
			Next
			
			' Add lookup name to array
			intArrMax = intArrMax + 1
			redim preserve objReports(intArrMax)
			objReports(intArrMax) = lookupname
			
		Next
	
	End If
        
        redim objReports(0)
        
 
Next

Open in new window

0
 
LVL 58

Expert Comment

by:tigermatt
ID: 22911938

And just to confirm, when I ran it on an OU where my Managers are located, it did find a duplicated entry where the first name and surname matched between the two.
0
 
LVL 11

Author Comment

by:bsharath
ID: 22911970
I get this

---------------------------
Windows Script Host
---------------------------
Script:      C:\Check all users if they have users and contacts as direct reportees.vbs
Line:      2
Char:      63
Error:      Unterminated string constant
Code:      800A0409
Source:       Microsoft VBScript compilation error

---------------------------
OK  
---------------------------

When i commented line 2 i get this

---------------------------
Windows Script Host
---------------------------
Script:      C:\Check all users if they have users and contacts as direct reportees.vbs
Line:      49
Char:      2
Error:      Unterminated string constant
Code:      800A0409
Source:       Microsoft VBScript compilation error

---------------------------
OK  
---------------------------
0
 
LVL 11

Author Comment

by:bsharath
ID: 22911971
I get this

---------------------------
Windows Script Host
---------------------------
Script:      C:\Check all users if they have users and contacts as direct reportees.vbs
Line:      2
Char:      63
Error:      Unterminated string constant
Code:      800A0409
Source:       Microsoft VBScript compilation error

---------------------------
OK  
---------------------------

When i commented line 2 i get this

---------------------------
Windows Script Host
---------------------------
Script:      C:\Check all users if they have users and contacts as direct reportees.vbs
Line:      49
Char:      2
Error:      Unterminated string constant
Code:      800A0409
Source:       Microsoft VBScript compilation error

---------------------------
OK  
---------------------------
0
 
LVL 58

Expert Comment

by:tigermatt
ID: 22912158

Can you copy and paste the whole script you are using to a comment here?
Thanks!
0
 
LVL 58

Expert Comment

by:tigermatt
ID: 22912163

I mean the VBS you have stored with the OU path in it?
0
 
LVL 11

Author Comment

by:bsharath
ID: 22912234
Here it is
' Set OU where the *Managers* can be found, below
'strOUPath = "' Set OU where the *Managers* can be found, below
strOUPath = "OU=Test,dc=Development,dc=Group,dc=co,dc=uk"
 
Set objOU = GetObject("LDAP://" & strOUPath)
 
Dim objReports()
 
For Each objUser in objOU
        
        intArrMax = 0
 
        If (TypeName(objUser.directReports) = "Variant()") Then
		
		WScript.Echo "Processing " & objUser.givenName & " " & objUser.sn & " for duplicated Direct Reports"
		
		For Each strValue in objUser.directReports
			
			' Fetch object for this direct report
			Set objReportee = GetObject("LDAP://" & strValue)
			
			lookupname = objReportee.givenName & " " & objReportee.sn
			
			' Loop through the list of users we've already seen to see if this one is duplicated
			For Each strAlreadyProcessed In objReports
				
				If (LCase(strAlreadyProcessed) = LCase(lookupname)) Then
					
					' Duplicate detected
					WScript.Echo "** Duplicate Detected: " & lookupname & " (Manager: " & objUser.cn & ") **"
				
				End If
				
			Next
			
			' Add lookup name to array
			intArrMax = intArrMax + 1
			redim preserve objReports(intArrMax)
			objReports(intArrMax) = lookupname
			
		Next
	
	End If
        
        redim objReports(0)
        
 
Next
"
 
Set objOU = GetObject("LDAP://" & strOUPath)
 
Dim objReports()
 
For Each objUser in objOU
	
	intArrMax = 0
 
	If TypeName(objUser.directReports) = "Variant()" Then
		
		
		For Each strValue In objUser.directReports
			
			Set objReport = GetObject("LDAP://" & strValue)
			lookupname = objReport.givenName & " " & objReport.sn
			
			For Each x In objReports
				If x = lookupname Then
					WScript.Echo "Direct Report: " & lookupname & " (Manager: " & objUser.cn & ") duplicated!"
				End If
			Next
			redim preserve objReports(intArrMax)
			objreports(intArrMax) = lookupname
			intArrMax = intArrMax + 1
			Set objReport = Nothing
			lookupname = ""
		Next
		
	End If
	
	redim objReports(0)
	
 
Next

Open in new window

0
 
LVL 11

Author Comment

by:bsharath
ID: 22912235
Here it is
' Set OU where the *Managers* can be found, below
'strOUPath = "' Set OU where the *Managers* can be found, below
strOUPath = "OU=Test,dc=Development,dc=Group,dc=co,dc=uk"
 
Set objOU = GetObject("LDAP://" & strOUPath)
 
Dim objReports()
 
For Each objUser in objOU
        
        intArrMax = 0
 
        If (TypeName(objUser.directReports) = "Variant()") Then
		
		WScript.Echo "Processing " & objUser.givenName & " " & objUser.sn & " for duplicated Direct Reports"
		
		For Each strValue in objUser.directReports
			
			' Fetch object for this direct report
			Set objReportee = GetObject("LDAP://" & strValue)
			
			lookupname = objReportee.givenName & " " & objReportee.sn
			
			' Loop through the list of users we've already seen to see if this one is duplicated
			For Each strAlreadyProcessed In objReports
				
				If (LCase(strAlreadyProcessed) = LCase(lookupname)) Then
					
					' Duplicate detected
					WScript.Echo "** Duplicate Detected: " & lookupname & " (Manager: " & objUser.cn & ") **"
				
				End If
				
			Next
			
			' Add lookup name to array
			intArrMax = intArrMax + 1
			redim preserve objReports(intArrMax)
			objReports(intArrMax) = lookupname
			
		Next
	
	End If
        
        redim objReports(0)
        
 
Next
"
 
Set objOU = GetObject("LDAP://" & strOUPath)
 
Dim objReports()
 
For Each objUser in objOU
	
	intArrMax = 0
 
	If TypeName(objUser.directReports) = "Variant()" Then
		
		
		For Each strValue In objUser.directReports
			
			Set objReport = GetObject("LDAP://" & strValue)
			lookupname = objReport.givenName & " " & objReport.sn
			
			For Each x In objReports
				If x = lookupname Then
					WScript.Echo "Direct Report: " & lookupname & " (Manager: " & objUser.cn & ") duplicated!"
				End If
			Next
			redim preserve objReports(intArrMax)
			objreports(intArrMax) = lookupname
			intArrMax = intArrMax + 1
			Set objReport = Nothing
			lookupname = ""
		Next
		
	End If
	
	redim objReports(0)
	
 
Next

Open in new window

0
 
LVL 58

Expert Comment

by:tigermatt
ID: 22912759

I see your problem. You have the script actually copied twice! If you look on line 49, you have a " mark which should not be there, and neither should anything after that point either.

Open up a clean Notepad and copy and paste the below, then save it. I've put the OU path in already for you.

-Matthew
' Set OU where the *Managers* can be found, below
strOUPath = "OU=Test,dc=Development,dc=Group,dc=co,dc=uk"
 
Set objOU = GetObject("LDAP://" & strOUPath)
 
Dim objReports()
 
For Each objUser in objOU
        
        intArrMax = 0
 
        If (TypeName(objUser.directReports) = "Variant()") Then
		
		WScript.Echo "Processing " & objUser.givenName & " " & objUser.sn & " for duplicated Direct Reports"
		
		For Each strValue in objUser.directReports
			
			' Fetch object for this direct report
			Set objReportee = GetObject("LDAP://" & strValue)
			
			lookupname = objReportee.givenName & " " & objReportee.sn
			
			' Loop through the list of users we've already seen to see if this one is duplicated
			For Each strAlreadyProcessed In objReports
				
				If (LCase(strAlreadyProcessed) = LCase(lookupname)) Then
					
					' Duplicate detected
					WScript.Echo "** Duplicate Detected: " & lookupname & " (Manager: " & objUser.cn & ") **"
				
				End If
				
			Next
			
			' Add lookup name to array
			intArrMax = intArrMax + 1
			redim preserve objReports(intArrMax)
			objReports(intArrMax) = lookupname
			
		Next
	
	End If
        
        redim objReports(0)
        
 
Next

Open in new window

0
 
LVL 11

Author Comment

by:bsharath
ID: 22912778
Sorry for that shall check and get back...
0
 
LVL 58

Expert Comment

by:tigermatt
ID: 22912782

It's not a problem, I like tracking bugs down and fixing them :-)
0
 
LVL 11

Author Comment

by:bsharath
ID: 22958508
Works Perfect now without the boxes how can i get the results to a file

With the user & Contact & Manager name

When found log the data to the file
0
 
LVL 58

Accepted Solution

by:
tigermatt earned 500 total points
ID: 22961165

Can't test it at the moment but try the following - it should do the trick. Specify the log file in strLog = "...".

-Matthew
Const ForWriting = 2
 
' Set OU where the *Managers* can be found, below
strOUPath = "OU=Test,dc=Development,dc=Group,dc=co,dc=uk"
 
'Log File path
strLog = "C:\logfile.log"
 
Set objOU = GetObject("LDAP://" & strOUPath)
Dim fso: Set fso = CreateObject("Scripting.FileSystemObject")
 
Set logFile = fso.OpenTextFile(strLog, ForWriting, true)
logFile.WriteLine vbCrLf & vbCrLf & "** SCRIPT RUN STARTING @ " & NOW() & " **"
 
Dim objReports()
 
For Each objUser in objOU
        
        intArrMax = 0
 
        If (TypeName(objUser.directReports) = "Variant()") Then
		
		logFile.WriteLine "Processing " & objUser.givenName & " " & objUser.sn & " for duplicated Direct Reports"
		
		For Each strValue in objUser.directReports
			
			' Fetch object for this direct report
			Set objReportee = GetObject("LDAP://" & strValue)
			
			lookupname = objReportee.givenName & " " & objReportee.sn
			
			' Loop through the list of users we've already seen to see if this one is duplicated
			For Each strAlreadyProcessed In objReports
				
				If (LCase(strAlreadyProcessed) = LCase(lookupname)) Then
					
					' Duplicate detected
					logFile.WriteLine "** Duplicate Detected: " & lookupname & " (Manager: " & objUser.cn & ") **"
				
				End If
				
			Next
			
			' Add lookup name to array
			intArrMax = intArrMax + 1
			redim preserve objReports(intArrMax)
			objReports(intArrMax) = lookupname
			
		Next
	
	End If
        
        redim objReports(0)
        
 
Next
 
logFile.WriteLine vbCrLf & "** ENDED PROCESSING OF RUN **" & vbCrLf & "**********************************" & vbCrLf & vbCrLf
Set fso = Nothing
Set logFile = Nothing

Open in new window

0
 
LVL 11

Author Comment

by:bsharath
ID: 22966335
Thank U worked perfect
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Debug script powershell wmi 3 20
Powershell GUI 11 63
Python sort list of tuples, skipping column 2 27
Help with Classic ASP - Parameterizing Query 16 24
This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
Learn the basics of lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

726 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