May 052011
 

Recently I was creating a new demo environment and had to create some AD users to use in my CRM deployment. I hate doing tedious repetative tasks one-by-one, and ended up using a modified version of the powershell script from: http://www.thejoyofcode.com/Creating_AD_user_accounts_in_PowerShell.aspx – so I figured I’d share it with everyone else so that when they need to mass create some users and just have their first and last name, this will help.

Here is the powerhsell code:

$domain = (get-addomain).distinguishedname
$path = "OU=Employees,$domain"
$employees = Get-ADObject -Filter {distinguishedname -eq $path}
If ( -not $employees) {
  $employees = $domain.Create("OrganizationalUnit", "ou=Employees")
  $employees.SetInfo()
}

$users = import-csv "C:\Scripts\usersToBeCreated.csv"
$ldappath = "LDAP://$path"
$container = [ADSI] $ldappath
$users | foreach {
    $first = $_.FirstName
    $last = $_.LastName
    $username = "$first" + "." + "$last"
    $email = "$username" + "@demo.local"
    $newUser = $container.Create("User", "cn=" + $username)
    $newUser.Put("sAMAccountName", $username)
    $newUser.Put("givenname",$first)
    $newUser.Put("sn",$last)
    $newUser.Put("mail",$email)
    $newUser.Put("description","Demo Account")
    $newUser.SetInfo()
    $newUser.psbase.InvokeSet('AccountDisabled', $false)
    $newUser.SetInfo()
    $newUser.SetPassword("somethingG00D!")
}

Hopefully that will help someone else save some time.

  10 Responses to “Quickly Create Users in Active Directory from CSV for Demo Environment”

Comments (7) Pingbacks (3)
  1. Hi, Carlton, we met a new problem now, and I guess it may cause of migration from CRM4 to CRM2011,
    in QueueItem detail form, if the date is upgrated from CRM4, “Worked By” field has data, but lack user’s display name.
    Check this thread, i did post some captures within it.

  2. And there is sth else i want to know, why there is no “Retrieve/RetrieveMultiple” Message On “QueueItem”. Thanks for you patience and answers.

 Leave a Reply

(required)

(required)

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>