Advertisement
Guest User

Untitled

a guest
Nov 26th, 2014
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. On Error Resume Next
  2.  
  3. Const ADS_SCOPE_SUBTREE = 4
  4. Const ForReading = 1
  5.  
  6. 'fichier generer avec AD-INFO SAMAccountName uniquement pour traité la job
  7. strCSV = "c:\2weekpast.csv"
  8. strDomain = "dc=chrg,dc=reg03,dc=rtss,dc=qc,dc=ca"
  9.  
  10. Set objFSO = CreateObject("Scripting.FileSystemObject")
  11. Set objFile = objFSO.OpenTextFile(strCSV, ForReading)
  12.  
  13. Do Until objFile.AtEndOfStream
  14.     strLine = objFile.ReadLine
  15.     arrLine = Split(strLine, ",")
  16.     strAccount = arrLine(0)
  17.     If LCase(strAccount) <> "samaccountname" Then  
  18.         Set objConnection = CreateObject("ADODB.Connection")
  19.         Set objCommand =   CreateObject("ADODB.Command")
  20.         objConnection.Provider = "ADsDSOObject"
  21.         objConnection.Open "Active Directory Provider"
  22.         Set objCommand.ActiveConnection = objConnection
  23.        
  24.  'protection anti buffer overflow, ne traiteras pas plus que 500 enregistrement
  25.         objCommand.Properties("Page Size") = 500
  26.         objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
  27.  
  28.         objCommand.CommandText = "SELECT AdsPath FROM 'LDAP://" & strDomain & _
  29.             "' WHERE objectCategory='user' AND samaccountname='" & strAccount & "'"  
  30.  
  31.         Set objRecordSet = objCommand.Execute
  32.  
  33.         objRecordSet.MoveFirst
  34.  
  35.         Do Until objRecordSet.EOF
  36.             strUserPath = objRecordSet.Fields("AdsPath").Value
  37.             Set objUser = GetObject(strUserPath)
  38.             objUser.AccountDisabled = True
  39.             objUser.SetInfo
  40.             objRecordSet.MoveNext
  41.         Loop
  42.     End If
  43. Loop
  44.  
  45. objFile.Close
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement