# # add_users.ps1 # # Written by Carol Wapshere, September 2008 # # Use to create one or more user accounts, including mailbox, home folder, profile folder # and required AD settings. # # Instructions: # #Â Â 1. Modify the add_users.csv file to include information about the users to add. #Â Â Â Â Â The file must have a header row and must include the following fields: #Â Â Â Â Â Â Â Â Â Â Â dn,UID,displayName,surname,givenName,password,mail,alias,description,UPN # #Â Â 2. Open the Exchange Management Shell # #Â Â 3. CD to C:\scripts and run add_users.ps1.
cat add_users.csv > unicode.csv # make utf8
import-csv unicode.csv | foreach {
write-host write-host write-host "Creating account for " $_.displayName $secureString = ConvertTo-SecureString $_.password -AsPlainText –Force
New-Mailbox -Name $_.displayName -displayName $_.displayName -Alias $_.alias -OrganizationalUnit 'bbhfgg.local/BBH/Users' -UserPrincipalName $_.UPN -SamAccountName $_.UID -FirstName $_.givenName -Initials '' -LastName $_.surname -Database 'MEXBBH01\First Storage Group\Mailbox Database' -password $secureString -ResetPasswordOnNextLogon $false
$ldapstring = "LDAP://" + $_.dn write-host $ldapstring $user = [ADSI]$ldapstring
$homeRoot = "\\filbbh01\Home$\" $profileRoot = "\\filbbh01\Profile$\" $homeShare = "\\filbbh01\" + $_.UID $homeDir = $homeRoot + $_.UID $profileDir = $profileRoot + $_.UID
write-host "Creating folder " $homeDir New-Item -path $homeRoot -name $_.UID -type directory $caclsCmd = "cacls " + $homeDir + " /g " + $_.UID + ":C backup:R" write-host $caclsCmd invoke-expression $caclsCmd
write-host "Creating folder " $profileDir New-Item -path $profileRoot -name $_.UID -type directory $caclsCmd = "cacls " + $profileDir + " /g " + $_.UID + ":C backup:R" write-host $caclsCmd invoke-expression $caclsCmd
write-host write-host "Setting AD attributes..."
write-host "Â Â Â description: " $_.description $user.Description = $_.description
write-host "Â Â Â homeDirectory: " $homeShare $user.Put("homeDirectory", $homeShare)
write-host "   homeDrive P:" $user.Put("homeDrive", "P:")
write-host "Â Â Â profilePath: " $profileDir $user.Put("profilePath", $profileDir)
$user.SetInfo()
} | out-file -filepath "c:\scripts\add_users.log" -encoding "UNICODE"