# Create mailbox to all users in a CSV based on the 3+3 naming policy.
# This will also create the user in AD
$parentcontainer = "contoso.com/container"
$homedirectory = "contoso.comusers$username"
# Prompt the user for password
$password = Read-Host "Enter password" -AsSecureString
# The following has to be done to import with european characters
cat "c:tempusers.csv" > c:templisttemp.csv
# Loop through the list and
# - replace european letters with o,a or e.
# - create username based on the 3+3 naming convention
# (three first letters in the firstname and lastname.)
# - all lower case
import-csv c:templisttemp.csv | foreach {
$username = ($_.firstname.substring(0,3) + $_.lastname.substring(0,3)).tolower()
$username = $username.replace("ø","o")
$username = $username.replace("å","a")
$username = $username.replace("æ","e")
# The following line can create the user if you do not need mailbox.
# new-qadUser -ParentContainer $parentcontainer -FirstName $_.firstname -LastName $_.lastname -DisplayName $($_.FirstName + " " + $_.LastName) -SamAccountName $username -Name $username -UserPrincipalName ($username + '@contoso.com') -whatif
# Create the mailbox
New-Mailbox -Alias $username -Name $($_.FirstName + " " + $_.LastName) -OrganizationalUnit $parentcontainer -UserPrincipalName ($username + '@contoso.com') -SamAccountName $username -FirstName $_.firstname -LastName $_.lastname -ResetPasswordOnNextLogon $false -password $password -whatif
}
Create mailbox to all users in a CSV based on the 3+3 naming policy
Leave a reply
