• Active Directory Scripts

     

     

    Creating Logon Scripts

    Logon scripts assign tasks to be performed as a user logs on to a system computer and can be created in a text editor using VBScript or Jscript batch language commands, which are supported by Windows Script Host (WSH). These scripts will carry out commands, set environment variables and executable programs. Commonly performed tasks include mapping network drives, collecting system information, updating software or virus signatures, or installing and setting default printers.

    VBScript is not just a scripting language of little use to systems administrators who must manage hundreds, sometimes thousands of computers in a setting. Used along with technologies such as Windows Management Instrumentation (WMI), and Active Directory Service Interfaces (ADSI), VBScript serves as a powerful language meant to facilitate creating sys admin tools. A single script will allow for complete control over many aspects of a computing environment.

    Active Directory scripts solutions can be accomplished in a few minutes with a simple text editor. There is a tremendous advantage with VBScript in being able to add to a script without having to start over from scratch. Start with a very simple script and add to it as the needs change and as proficiency with the language is gained.

    Getting Started

    It is recommended that this process is begun at a Windows Server domain controller, or a suitable alternative such as Remote Desktop. To keep things simple, it is best to start with as few obstacles as is possible. Another option is to work these scripts from an XP machine but not as an administrator.

    The following is a demonstration that will create 1,000 user accounts. They are designated UserNo1 through UserNo1,000 within the Users container (cn) in Active Directory. This is a useful test scenario for multiple user accounts.

    1. Set objRootDSE = GetObject("LDAP://rootDSE")
    2. Set objContainer = GetObject("LDAP://cn=Users," & _
    3. objRootDSE.Get("defaultNamingContext"))
    4. For i = 1 To 1000
    5. Set objLeaf = objContainer.Create("User", "cn=UserNo" & i)
    6. objLeaf.Put "sAMAccountName", "UserNo" & i
    7. objLeaf.SetInfo
    8. Next
    9. WScript.Echo "1000 Users created."

    What is crucial here is the command that allows the script to work within any domain:

    1. GetObject(“LDAP://rootDSE”)

    This is what will bind WSH/VBScript to Active Directory. What follows is the container, or where that user will be born.

    sAMAccountName is the control over the logon name -- what the user enters in the dialog box in the logon sequence.

    Running Active Directory scripts that have been copied, pasted into Notepad or VBScript editor and then saved as .vbs file extension will report back the versions of WSH, WMI, VBScript and ADSI installed on the computer. Any responses that return blank indicate the technology was not installed.

     

    query Active Directory And be sure to check out Keck Web Active Directory Manager. 
    Try it
     for free!

     

    Need to dump the entire contents of your users list with one click?
    Download our free Active Directory reporting tool!
     
     

    Share this

  • Try Exchange360 Now

    Download a 30-day fully functional trial of Exchange360.
    Download Now

    Buy Exchange360 Now

    Get going with Exchange360 today including 24/7 support.
    Buy Now - $399