最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

PowerShell Script for Importing Contacts to Outlook Fails to Set Email Address Correctly - Stack Overflow

programmeradmin3浏览0评论

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
  • Did you try checking proxyaddresses and mail attribute of the user? Pls chk the link learn.microsoft/en-us/troubleshoot/entra/entra-id/… – ErkinD39 Commented Mar 21 at 12:34
  • SMTP:[email protected] is a wrong format. It needs to be [email protected] – Dmitry Streblechenko Commented Mar 21 at 15:42
  • You say "I attempted using different variations of the email address (SMTP:[email protected]), but the problem persists.", but do not show what these attempts were like. Did you try without SMTP: as Dmitry suggested? – Theo Commented Mar 23 at 11:44
Add a comment  | 

1 Answer 1

Reset to default 0

The 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)

发布评论

评论列表(0)

  1. 暂无评论