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
Active Directory Tasks by using Powershell
Create OU
$strCL="organizationalUnit"
$strOUName="ou=TestOU"
$objADSI=[ADSI]"LDAP://dc=fabrikam,dc=com"
$objOU=$objADSI.create($strCL,$strOUName)
$objOU.setinfo()
Create User
$strCL="User"
$strName="Cn=Erkan"
$objADSI=[ADSI]"LDAP://ou=TestOU,dc=fabrikam,dc=com"
$objUser=$objADSI.create($strCL,$strName)
$$objUser.Put("sAMAccountName","Erkan")
$objUser.setinfo()
Modify User Properties
$objUser=[ADSI]"LDAP://cn=Erkan,ou=TestOU,dc=fabrikam,dc=com"
$objUser.put("sAMAccountName","Erkan")
$objUser.put("givenName","Sezgin")
$objUser.put("DisplayName","Erkan Sezgin")
$objUser.put("telephoneNumber","216-111-1111")
$objUser.put("mail","erkan.sezgin@fabrikam.com")
$objUser.setinfo()
Other Attributes;
wwwHomePage,description,streetAddress,postOfficeBox,l,st,postalcode,CountryCode
homeDirectory,homeDrive,profilePath,scriptPath,homePhone,title
put what you want,but dont forget the $setinfo() method at the end.