I'm working with a PowerShell script that imports Active Directory users to Outlook contacts. The script successfully imports various attributes, but the email addresses are not set correctly. The issue seems to be with the format of the email address when it's being assigned to the Email1Address property in the Outlook contact.
Steps Taken: I exported Active Directory users into a CSV file, including email addresses and other attributes. I use a PowerShell script to loop through the CSV data and add or update contacts in Outlook. When updating or creating new contacts, I assign the email address using $user.'E-mail Address', but the contact's email field remains empty or is incorrectly formatted.
I ensured the Email1Address is populated with the correct email address in the CSV
I attempted using different variations of the email address (SMTP:[email protected]), but the problem persists.
foreach ($user in $csvData) {
Write-Output "Processing user: $($user.'E-mail Address')"
$existingContact = $ContactsFolder.Items | Where-Object { $_.Email1Address -eq $user.'E-mail Address' }
if ($existingContact) {
Write-Output "Updating existing contact: $($existingContact.Email1Address)"
$existingContact.FirstName = $user.'First Name'
$existingContact.MiddleName = $user.'Middle Name'
$existingContact.LastName = $user.'Last Name'
$existingContact.Email1Address = $user.'E-mail Address'
$existingContact.HomeTelephoneNumber = $user.'Home Phone'
$existingContact.BusinessTelephoneNumber = $user.'Business Phone'
$existingContact.MobileTelephoneNumber = $user.'Mobile Phone'
$existingContact.BusinessFaxNumber = $user.'Business Fax'
$existingContact.JobTitle = $user.'Job Title'
$existingContact.Department = $user.'Department'
$existingContact.CompanyName = $user.'Company'
$existingContact.OfficeLocation = $user.'Office Location'
$existingContact.ManagerName = $user.'Manager''s Name'
$existingContact.BusinessAddressStreet = $user.'Business Street'
$existingContact.BusinessAddressCity = $user.'Business City'
$existingContact.BusinessAddressState = $user.'Business State'
$existingContact.BusinessAddressPostalCode = $user.'Business Postal Code'
$existingContact.BusinessAddressCountry = $user.'Business Country/Region'
$existingContact.Save()
} else {
Write-Output "Creating new contact for: $($user.'E-mail Address')"
$NewContact = $ContactsFolder.Items.Add("IPM.Contact")
$NewContact.FirstName = $user.'First Name'
$NewContact.MiddleName = $user.'Middle Name'
$NewContact.LastName = $user.'Last Name'
$NewContact.Email1Address = $user.'E-mail Address'
$NewContact.HomeTelephoneNumber = $user.'Home Phone'
$NewContact.BusinessTelephoneNumber = $user.'Business Phone'
$NewContact.MobileTelephoneNumber = $user.'Mobile Phone'
$NewContact.BusinessFaxNumber = $user.'Business Fax'
$NewContact.JobTitle = $user.'Job Title'
$NewContact.Department = $user.'Department'
$NewContact.CompanyName = $user.'Company'
$NewContact.OfficeLocation = $user.'Office Location'
$NewContact.ManagerName = $user.'Manager''s Name'
$NewContact.BusinessAddressStreet = $user.'Business Street'
$NewContact.BusinessAddressCity = $user.'Business City'
$NewContact.BusinessAddressState = $user.'Business State'
$NewContact.BusinessAddressPostalCode = $user.'Business Postal Code'
$NewContact.BusinessAddressCountry = $user.'Business Country/Region'
$NewContact.Save()
}
}
I found that it needs to be in EX type, tried manually setting it for the user that didn't work either
I'm working with a PowerShell script that imports Active Directory users to Outlook contacts. The script successfully imports various attributes, but the email addresses are not set correctly. The issue seems to be with the format of the email address when it's being assigned to the Email1Address property in the Outlook contact.
Steps Taken: I exported Active Directory users into a CSV file, including email addresses and other attributes. I use a PowerShell script to loop through the CSV data and add or update contacts in Outlook. When updating or creating new contacts, I assign the email address using $user.'E-mail Address', but the contact's email field remains empty or is incorrectly formatted.
I ensured the Email1Address is populated with the correct email address in the CSV
I attempted using different variations of the email address (SMTP:[email protected]), but the problem persists.
foreach ($user in $csvData) {
Write-Output "Processing user: $($user.'E-mail Address')"
$existingContact = $ContactsFolder.Items | Where-Object { $_.Email1Address -eq $user.'E-mail Address' }
if ($existingContact) {
Write-Output "Updating existing contact: $($existingContact.Email1Address)"
$existingContact.FirstName = $user.'First Name'
$existingContact.MiddleName = $user.'Middle Name'
$existingContact.LastName = $user.'Last Name'
$existingContact.Email1Address = $user.'E-mail Address'
$existingContact.HomeTelephoneNumber = $user.'Home Phone'
$existingContact.BusinessTelephoneNumber = $user.'Business Phone'
$existingContact.MobileTelephoneNumber = $user.'Mobile Phone'
$existingContact.BusinessFaxNumber = $user.'Business Fax'
$existingContact.JobTitle = $user.'Job Title'
$existingContact.Department = $user.'Department'
$existingContact.CompanyName = $user.'Company'
$existingContact.OfficeLocation = $user.'Office Location'
$existingContact.ManagerName = $user.'Manager''s Name'
$existingContact.BusinessAddressStreet = $user.'Business Street'
$existingContact.BusinessAddressCity = $user.'Business City'
$existingContact.BusinessAddressState = $user.'Business State'
$existingContact.BusinessAddressPostalCode = $user.'Business Postal Code'
$existingContact.BusinessAddressCountry = $user.'Business Country/Region'
$existingContact.Save()
} else {
Write-Output "Creating new contact for: $($user.'E-mail Address')"
$NewContact = $ContactsFolder.Items.Add("IPM.Contact")
$NewContact.FirstName = $user.'First Name'
$NewContact.MiddleName = $user.'Middle Name'
$NewContact.LastName = $user.'Last Name'
$NewContact.Email1Address = $user.'E-mail Address'
$NewContact.HomeTelephoneNumber = $user.'Home Phone'
$NewContact.BusinessTelephoneNumber = $user.'Business Phone'
$NewContact.MobileTelephoneNumber = $user.'Mobile Phone'
$NewContact.BusinessFaxNumber = $user.'Business Fax'
$NewContact.JobTitle = $user.'Job Title'
$NewContact.Department = $user.'Department'
$NewContact.CompanyName = $user.'Company'
$NewContact.OfficeLocation = $user.'Office Location'
$NewContact.ManagerName = $user.'Manager''s Name'
$NewContact.BusinessAddressStreet = $user.'Business Street'
$NewContact.BusinessAddressCity = $user.'Business City'
$NewContact.BusinessAddressState = $user.'Business State'
$NewContact.BusinessAddressPostalCode = $user.'Business Postal Code'
$NewContact.BusinessAddressCountry = $user.'Business Country/Region'
$NewContact.Save()
}
}
I found that it needs to be in EX type, tried manually setting it for the user that didn't work either
Share Improve this question edited Mar 23 at 11:45 Theo 61.5k8 gold badges27 silver badges46 bronze badges asked Mar 21 at 11:12 Din SadovicDin Sadovic 1 3 |1 Answer
Reset to default 0The problem wasn't in the email format it was wrong kind of format so this
$NewContact.Email1Address = $user.'E-mail Address isn't the same as
$NewContact.Email1Address = "$($user.'E-mail Address')" (that's the correct)
SMTP:[email protected]
is a wrong format. It needs to be[email protected]
– Dmitry Streblechenko Commented Mar 21 at 15:42SMTP:
as Dmitry suggested? – Theo Commented Mar 23 at 11:44