none
Bulk Updates to Active Directory Sites & Services RRS feed

  • Question

  • Hi;

    Can someone assist me, how to create a script to bulk updates to Windows 2008 R2 Active Directory & Services? Especially on subnets lists..

    Best Regards
    MMuhammimi


    MMO
    Thursday, January 21, 2010 7:53 AM

All replies

  • Hi MMuhammimi

    Thanks for the post here.

    Everything is simple when you have the tools. Here is a script to get you going. However, this script has some assumptions and you will need to make some modifications. It gives you a starting point. If you have more attributes just add them in and expand it.

    I hope it works for you.
    Here is the script:
    ==============================
    ' ---------------------------------------------------
    ' Script: createusers2.vbs
    ' Input: It uses a CSV file with layout logonname,firstname,lastname,password


    Option Explicit

    Dim sCSVFileLocation
    Dim sCSVFile
    Dim objFSO
    Dim objFile
    Dim strLine
    Dim strItems
    Dim oNewUser

    ' ----------LDAP connection variables----------
    Dim oRootLDAP
    Dim oContainer

    ' ----------Other variables--------------------
    Dim sLogon
    Dim sFirstName
    Dim sLastName
    Dim sDisplayName
    Dim sPassword
    Dim nPwdLastSet
    Dim nUserAccountControl ' Used to enable the account
    Dim sDomain

    ' ----------Modify this to match your company's AD domain----------
    sDomain="corp.myDomain.com"

    ' ----------Input file location----------
    sCSVFileLocation = "C:\myUserBase"
    ' ----------Full path to input file----------
    sCSVFile = sCSVFileLocation&"myusers.csv"

    ' ----------Commands used to open the CSV file and select all of the records----------
    set objFSO = CreateObject("Scripting.FileSystemObject")
    set objFile = objFSO.OpenTextFile(sCSVFile, 1)

    ' ----------Create a connection to the Active Directory Users container.----------

    Set oContainer = GetObject("LDAP://mycorpdc/OU=Import,dc=corp,dc=myDomain,dc=com")

    ' ----------Allows processing to continue even if an error occurs (i.e. dup user)----------
    on error resume next

    Do Until objFile.AtEndOfStream ' Reads the values (cells) in the sInputFile file.

    ' --------- Start creating user account----------
    ' Read variable information from the CSV file
    ' and build everything needed to create the account
    strLine = objFile.ReadLine
    strItems = split(strLine,",")

    sLogon = strItems(0)
    sFirstName = strItems(1)
    sLastName = strItems(2)
    sDisplayName = sFirstName&" "&sLastName
    sPassword = strItems(3)

    ' ----------Build the User account----------
    Set oNewUser = oContainer.Create("User","cn="&sFirstName&" "&SLastName)

    oNewUser.put "sAMAccountName",lcase(sLogon)
    oNewUser.put "givenName",sFirstName
    oNewUser.put "sn",sLastName
    oNewUser.put "UserPrincipalName",lcase(SLogon)&"@"&sDomain
    oNewUser.put "DisplayName",sDisplayName
    oNewUser.put "name",lcase(sLogon)

    ' ----------Write this information into Active Directory so we can----------
    ' modify the password and enable the user account
    oNewUser.SetInfo

    ' ----------Change the users password----------
    oNewUser.SetPassword sPassword
    oNewUser.Put "pwdLastSet", -1

    Regards 

    Arjuna V
    ______________________________________________________________________________________

    ***************Please mark this as answer, if it is really helped. Or Post back****************

    _____________________________________________________________________________________

    • Proposed as answer by Arjuna V Monday, February 8, 2010 6:56 PM
    Wednesday, February 3, 2010 5:37 PM