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
271 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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Sums of coloumns in html/java 15 76
script issue to add permissions to the registry hive 2 38
Compile Error 7 51
Can we display time in 12 hr format using batch file ? 2 30
This script will sweep a range of IP addresses (class c only, 255.255.255.0) and report to a log the version of office installed. What it does: 1.)      Creates log file in the directory the script is run from (if it doesn't already exist) 2.)      Sweep…
Batch, VBS, and scripts in general are incredibly useful for repetitive tasks.  Some tasks can take a while to complete and it can be annoying to check back only to discover that your script finished 5 minutes ago.  Some scripts may complete nearly …
Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

778 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