Ok. This is the code I am using. I am not an expert in coding. just using a code available and tweaking as per my requirement. Tried different methods like .accountdisabled = True, but it didn't worked. Hope you can assist me to complete this.
'Script deletes Users from a csv file.
'csv format is strsAMUserName,Whatever
'Written by Andrew hill and Carl Harrison - Microsoft MCS
'this script is offered with no warranty
'On Error Resume Next 'used in case user not found
Option Explicit
Const ForReading = 1
Const ForWriting = 2
Dim strL, spl1, strOU, strUserCN, strName
Dim objFSO, objInputFile,objOutputFile
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objInputFile = objFSO.OpenTextFile("c:\Temp\dn.txt", ForReading) 'your csv file
Set objOutputFile = objFSO.OpenTextFile("c:\Temp\status.txt", ForWriting, True) 'your output file
'wscript.echo "script started"
'extract from csv file
Do until objInputFile.AtEndOfStream
strL = objInputFile.ReadLine
spl1 = Split(strL, ",")
strName = (spl1(0))
If UserExists(strName) = True Then
If objRecordSet.Fields("sAMAccountname").Value = strsAMUserName Then
UserExists = True
Set objLDAPUser = GetObject(objRecordSet.Fields("adspath").Value)
strOU = objLDAPUser.Parent
strUserCN = objRecordSet.Fields("CN").Value
End If
Else
'WScript.Echo strsAMUserName & " User doesn't exist or Duplicate sAMAccountName"
objOutputFile.WriteLine "UserID " & strName & " not found "
UserExists = False
strUserCN = ""
strOU = ""
End If
objRecordSet.Close
Set objConnection = Nothing
Set objCommand = Nothing
Set objRootLDAP = Nothing
Set objLDAPUser = Nothing
Set objRecordSet = Nothing
end function
Sub DelUser
Dim objOU
Set objOU = GetObject(strOU)
objOU.Delete "User", "cn=" & strUserCN & ""
'objOU.Delete "User", "cn=" & strUserCN & "" ' instead of delete I want to disable the user
WScript.Echo strName & " (CN=" & strUserCN & ") has been deleted."
Set ObjOU = Nothing
strUserCN = ""
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.