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
264 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
Comment Utility

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
Comment Utility
Thank U shall check and get back...
0
 
LVL 11

Author Comment

by:bsharath
Comment Utility
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
 
LVL 58

Expert Comment

by:tigermatt
Comment Utility

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

Will work on and get back.
0
 
LVL 58

Expert Comment

by:tigermatt
Comment Utility

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
Comment Utility

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
Comment Utility
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
Comment Utility
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
Comment Utility

Can you copy and paste the whole script you are using to a comment here?
Thanks!
0
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
LVL 58

Expert Comment

by:tigermatt
Comment Utility

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

Author Comment

by:bsharath
Comment Utility
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
Comment Utility
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
Comment Utility

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
Comment Utility
Sorry for that shall check and get back...
0
 
LVL 58

Expert Comment

by:tigermatt
Comment Utility

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

Author Comment

by:bsharath
Comment Utility
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
Comment Utility

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
Comment Utility
Thank U worked perfect
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question (Question ID  (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_28455246.html)28455246) Here (http…
How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
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…
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 …

762 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

13 Experts available now in Live!

Get 1:1 Help Now