How can I add users from a CSV file to Active Directory (AD) and Exchange using PowerShell?

How to add user group to Active Directory from csv file using PowerShell?

The csv file will contain the first, last, email, temporary password and description for users. OU, permissions, etc. Can be hardcoded.

The script should also add the Exchange 2007 mailbox.

0


a source to share


2 answers


The csv file must contain a header line 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'
}

      

+1


a source


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 the New-Mailbox cmdlet

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

+1


a source







All Articles