# Create User Accounts & Mailboxes According to Information in contacts.csv (CSV Formatted)
# NOTE: Be sure that the Contacts.csv file resides in the same directory as the script when running.
# $_. (defined by $entry) calls the column in the CSV (e.g. $_.First calls the data from csv column titled First)
# $_.First is First Name
# $_.Last is Last Name
# $DN is Display Name
# $uLogin is User Login Name
# $OU is the Organizational Unit for User Objects (String Value enclosed in '')
# $Domain is the UPN Domain Name (either internal Domain Name or Public Domain Name if added as additional UPN Domain in Domains & Trusts, string value enclosed in '')
# $Server is the Database Serer Name (String value enclosed in '')
# $SG is the Storage Group Name for hosting Mailboxes
# $MDB is the Mailbox Database Name for hosting Mailboxes
# Define Common Variables
$OU = 'Contacts'
# Call CSV File & Create Mailboxes
Write-host "Creating Contacts..."
import-csv 'contacts.csv' |
foreach{
$entry = $_
$DN = $_.First+" " +$_.Last;
$Alias = $_.First+"_" +$_.Last
New-MailContact $DN -DisplayName $DN -FirstName $_.First -LastName $_.Last -organizationalunit $OU -Alias $Alias -ExternalEmailAddress $_.email
Set-Contact $DN -Company $_.Company -Title $_.Title -Department $_.Department -Fax $_.Fax -MobilePhone $_.Mobile -Office $_.Location -Phone $_.Tel -PostalCode $_.Zip -PostOfficeBox $_.POBox -City $_.City -StreetAddress $_.StreetAdd -CountryorRegion $_.Country
Write-Host 'OU =' $OU
Write-host 'First Name =' $_.First
Write-Host 'Last Name =' $_.Last
write-host 'Display Name =' $DN
Write-Host 'Alias =' $Alias
Write-Host 'Email Address =' $_.Email
Write-Host 'Company =' $_.Company
Write-Host 'Office =' $_.Location
Write-Host 'Title =' $_.Title
Write-Host 'Department =' $_.Department
Write-Host 'Telephone =' $_.Tel
Write-Host 'Fax =' $_.Fax
Write-Host 'Mobile No. =' $_.Mobile
}
|