Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
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
Medium Priority
?
287 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
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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 2000 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
A quick Powershell script I wrote to find old program installations and check versions of a specific file across the network.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

580 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