Tag: active directory

  • Bulk import Active Directory Users and Create Email address

    I was tasked at work to come up with a way to import new Active Directory accounts and Exchange 2007 email boxes.  I decided to use the Exchange 2007 Management Console which uses lots of powershell.

    Here is what I came up with:

    This command is used to import users from a CSV file into Exchange 2007 creating email boxes and user accounts.  User accounts are set to change password upon first log in.

    Created 20090630, By Mario Leal

    NOTES:

    • Command must be copied and pasted into the Exchange Management Console.
    • You must edit “C:\CSV\users.csv” to be the the location of your CSV file.
    • The CSV file must not have an empty line at the end of the file.
    • Duplicates will error, you must watch screen to catch them.
    • Empty middle initial in CSV needs one ” to represent blank.
    • Output file (output.txt) will give a list of successful imports.

    Schema (first Line) used for CSV file with an example (second line):
    alias,Name,UPN,password,givenName,surname,middleI
    maleal,”Mario Leal”,email@address.whatever,somepassword,Mario,Leal,A

    Reference URLs:

    http://social.technet.microsoft.com/Forums/en-US/exchangesvradmin/thread/2582c672-cddb-4446-9329-889139ebb346
    http://www.exchangepedia.com/blog/2006/11/exchange-server-2007-bulk-creation-of.html
    http://exchangepedia.com/blog/2006/12/bulk-mailbox-enabling-users-exchange-shell.html

    —commandstart—
    Import-CSV c:\CSV\users.csv | foreach {

    $secureString = ConvertTo-SecureString -string $_.password -AsPlainText –Force

    new-mailbox -alias $_.alias -name $_.name -userPrincipalName $_.UPN -FirstName $_.givenName -LastName $_.surname -Initials $_.middleI -database “Students” -org TEST -Password $securestring -ResetPasswordOnNextLogon $true

    } | out-file -filepath “c:\CSV\Output.txt”
    —commandend—

    Related Links:

  • VBS Scripts

    At my job, we are moving to all vbs scripts for our login scripts.

    Here are some that map network drives:

    —-begin script—-
    dim wshnetwork
    set wshnetwork = wscript.createobject(“wscript.network”)
    ON ERROR RESUME NEXT
    wshnetwork.removenetworkdrive “Z:”
    netshare = “\\servername\sharename”
    wshnetwork.mapnetworkdrive “Z:”,netshare
    —-end script—-

    Don’t forget “ON ERROR RESUME NEXT” because the script will die on any errors…like if the user doesn’t have a drive mapped called “z.”  This would prevent it actually being mapped.

    Here’s another script that connects a printer and sets that printer to default.

    —-begin script—-
    Set objNetwork = CreateObject(“WScript.Network”)
    objNetwork.AddWindowsPrinterConnection “\\printerservername\printername”
    objNetwork.SetDefaultPrinter “\\printerservername\printername”
    —-end script—-

    Enjoy!

    Mario

    Related links: