bsharath
asked on
This script that find Direct reportees who have the contact and users within them. Need to remove the User account.
Hi,
This script that find Direct reportees who have the contact and users within them. Need to remove the User account.
this code is from Matthew.
Need to be able to remove the contact or User.
Please even suggest on what to remove the contact or user Nt account and add that feature in the below script.
REgards
Sharath
This script that find Direct reportees who have the contact and users within them. Need to remove the User account.
this code is from Matthew.
Need to be able to remove the contact or User.
Please even suggest on what to remove the contact or user Nt account and add that feature in the below script.
REgards
Sharath
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
ASKER
Thank you Matthew
I get this
** SCRIPT RUN STARTING @ 11/18/2008 8:20:49 AM **
** ENDED PROCESSING OF RUN **
************************** ********
Nothing else gets logged...
I get this
** SCRIPT RUN STARTING @ 11/18/2008 8:20:49 AM **
** ENDED PROCESSING OF RUN **
**************************
Nothing else gets logged...
ASKER
Thank you Matthew
I get this
** SCRIPT RUN STARTING @ 11/18/2008 8:20:49 AM **
** ENDED PROCESSING OF RUN **
************************** ********
Nothing else gets logged...
I get this
** SCRIPT RUN STARTING @ 11/18/2008 8:20:49 AM **
** ENDED PROCESSING OF RUN **
**************************
Nothing else gets logged...
Is that in Logging mode? (I.e. just running the script normally?) If you go back to the old script at the start of the question and run it in the same OU, do you get some output? At least then we'll know exactly where the problem is!
ASKER
I havent changed any thing in the script should i change?
ASKER
I havent changed any thing in the script should i change?
ASKER
Matthew do you mean you want me to run the main code?
Yes when i ran the accepted code it showed that a user has duplicates
Yes when i ran the accepted code it showed that a user has duplicates
What I meant was if you try to run the code below, do you get the expected duplicates? The code below is without the delete feature, so I just need to track down if it is the delete feature causing this or not.
Sorry for not replying sooner! Not at my desk for a while today.
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
ASKER
Yes Matthew i get 60 + duplicates populated in the txt file.
When i run this script with a 2 i get some removed but not all.
I gave it some time to even see if its replication time. But still some are not removed.
In one user there were 3 duplicated where 2 were removed and 1 still there.
I even ran it 3 times but still all do not get removed...
When i run this script with a 2 i get some removed but not all.
I gave it some time to even see if its replication time. But still some are not removed.
In one user there were 3 duplicated where 2 were removed and 1 still there.
I even ran it 3 times but still all do not get removed...
ASKER
Yes Matthew i get 60 + duplicates populated in the txt file.
When i run this script with a 2 i get some removed but not all.
I gave it some time to even see if its replication time. But still some are not removed.
In one user there were 3 duplicated where 2 were removed and 1 still there.
I even ran it 3 times but still all do not get removed...
When i run this script with a 2 i get some removed but not all.
I gave it some time to even see if its replication time. But still some are not removed.
In one user there were 3 duplicated where 2 were removed and 1 still there.
I even ran it 3 times but still all do not get removed...
ASKER
Matthew does this script remove or delete?
ASKER
Matthew does this script remove or delete?
Hi Sharath,
Not the latest script I posted but the one above is the one which deleted. Bear in mind that it will only delete NTLogins if it finds a duplicate - it won't go and delete the contact too. Is this what you want? Only ntlogin deleted if a duplicate is found?
-Matthew
ASKER
Sorry matthew for not being clear on giving you info.
Actually i want to remove the user not delete the user
Say i have 2 guys who report to me. Both the NTlogin and contact is added. So i want to remove NTlogin so just the contact is shown.
In some cases we have both shown which is of no use. I just want to remove not delete.
I ended up deleting few logins but no problem i managed creating them back... :-))
Actually i want to remove the user not delete the user
Say i have 2 guys who report to me. Both the NTlogin and contact is added. So i want to remove NTlogin so just the contact is shown.
In some cases we have both shown which is of no use. I just want to remove not delete.
I ended up deleting few logins but no problem i managed creating them back... :-))
ASKER
Sorry matthew for not being clear on giving you info.
Actually i want to remove the user not delete the user
Say i have 2 guys who report to me. Both the NTlogin and contact is added. So i want to remove NTlogin so just the contact is shown.
In some cases we have both shown which is of no use. I just want to remove not delete.
I ended up deleting few logins but no problem i managed creating them back... :-))
Actually i want to remove the user not delete the user
Say i have 2 guys who report to me. Both the NTlogin and contact is added. So i want to remove NTlogin so just the contact is shown.
In some cases we have both shown which is of no use. I just want to remove not delete.
I ended up deleting few logins but no problem i managed creating them back... :-))
I see, so the script was working, just not doing the right thing. I'll have a look as soon as work here goes quieter!
ASKER
Yes Matthew
I want it to just be removed not deleted....
I want it to just be removed not deleted....
ASKER
Yes Matthew
I want it to just be removed not deleted....
I want it to just be removed not deleted....
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank U
Hi Sharath,
This will do it. When you run the script, you will need to specify a parameter on the command line. There are two modes: logging mode and deletion mode. I would suggest you run it in the logging mode first (just run it normally as you have been doing for any VBS script for logging mode). In this mode, it simply checks through and records any duplicates it finds in the log file. Once you check the duplicates list, you should then run the script in delete mode by entering a 2 at the prompt (i.e. cscript C:\myscript.vbs 2). By doing this, the script will then go through and delete all the NTLogins for the duplicated accounts which were previously logged. It adds this change to the log.
Let me know if you need any more changes, and remember, don't run it in mode 2 first, otherwise it will delete all the duplicate accounts!
Matthew
Open in new window