views:

2088

answers:

3

How would one add a group of users to Active Directory from a csv file using PowerShell?

The csv file would contain the first, last, email, temp password, and description for the users. The OU, permissions, and etc. could be hard coded.

The script should also add an Exchange 2007 email box.

+1  A: 

Create a new user (From here)

$newUser = $usersOU.Create("user","cn=MyNewUser")
$newUser.put("title", "PowerShell Test Account")
$newUser.put("employeeID", 123)
$newUser.put("description", "Test User Account for LazyAdmin Demo")
$newUser.SetInfo()

Using New-Mailbox cmdlet

Using Import-CSV cmdlet (its PowerShell 2.0, but mostly relevant to 1.0)

Shay Erlichmen
A: 

The csv file should contain a header row with all the field names.

Here is the code:

$Users = Import-Csv ".\UsersFile.csv"
foreach ($User in $Users)
{
    New-Mailbox -Name $User.Name -Alias $User.MailboxAlias `
        -OrganizationalUnit $User.OU `
        -UserPrincipalName $User.UPN -SamAccountName $User.UserName `
        -FirstName $User.First -Initials $USer.Initial -LastName $User.Last `
        -Password $User.Password -ResetPasswordOnNextLogon $false `
        -Database 'MailboxDatabaseFilename'
}
Matt Spradley