Const ADS_PROPERTY_UPDATE = 2
Ldapstr1 = "LDAP://w2k3-dc/dc=XXXX,dc=com"
Ldapstr2 = "LDAP://w2k3-dc.XXXX.com"
Set conn = CreateObject("ADODB.Connection")
conn.Provider = "ADSDSOObject"
conn.Open "ADS Provider"
const outputfile="c:\updateResult.txt"
Set wshShell = WScript.CreateObject ("WSCript.shell")
Set fso = CreateObject("Scripting.FileSystemObject")
Set f1 = fso.OpenTextFile (outputfile, 2, True)
On Error Resume Next
Set objExcel = CreateObject("Excel.Application")
If (Err.Number <> 0) Then
On Error GoTo 0
Wscript.Echo "Excel not installed."
Wscript.Quit
End If
On Error GoTo 0
strExcelPath = "c:\modify.xls"
objExcel.WorkBooks.Open strExcelPath
Set objSheet = objExcel.ActiveWorkbook.Worksheets(1)
' ilk satır başlık bilgisi,ikinci satırdan başlar.
intRow = 2
Do While objSheet.Cells(intRow, 1).Value <> ""
strCurrentSAM = objSheet.Cells(intRow, 1).Value
strNewSAM = objSheet.Cells(intRow, 2).Value
Set rs = conn.Execute( _
"<" & Ldapstr1 & ">;" _
& "(&(objectClass=User)(samAccountName="& strCurrentSAM &
"));Name,distinguishedName;subtree")
If (rs.recordcount = 1) then
strName = rs.Fields(0).Value
strdistinguishedName = rs.Fields(1).Value
Set objItem = GetObject(Ldapstr2 & "/" & strdistinguishedName)
objItem.put "samAccountName", strNewSAM
objItem.setinfo
set objItem = nothing
set rs = nothing
f1.Write strName & "," & strCurrentSAM & "," & strNewSAM & "," & "Done" &
VbCrLf
else
f1.Write strCurrentSAM & "," & "User not found" & VbCrLf
end if
intRow = intRow + 1
Loop
objExcel.ActiveWorkbook.Close
objExcel.Application.Quit
Set objExcel = Nothing
Set objSheet = Nothing
f1.close
conn.Close
Wscript.Echo "Done"
Modify Users sAMAccountName from Excel file
Etiketler:
adsdsoobject,
ADSI,
excel,
modify user,
samaccountname