none
Using Powershell to import contacts into O365 RRS feed

  • Question

  • Hello,

    I have been using this guide created by Steven Goodman

    http://www.stevieg.org/2010/07/using-powershell-to-import-contacts-into-exchange-and-outlook-live/

    I’ve been searching for some help but came up with none. When using the script to import .csv to O365 mailboxes with users created through local AD sync, the email address of the users in the same organisation, in the display email is shown as “xx xx” . External users email display name comes out as their email addresses however.

    However with uploading the same .csv to a non-AD synced email account. The display name would appear as the normal email address.

    Is there a way to show the emails in contacts displayed, in the same organisation as their email addresses instead of this “LegacyExchangeDN”?

    Appreciate the inputs from any personnel that can shed some light on this or guide me along the way and once again Steve for taking the time out to create this!

    Best,
    Russ W.

    Friday, December 9, 2016 8:13 AM

Answers

  • You need to set the extended properties rather then the strongly typed one to stop is resolving the address from the Gal eg try changing

                        "Email"
                        {
                            $ExchangeContact.EmailAddresses[[Microsoft.Exchange.WebServices.Data.EmailAddressKey]::($MappingArray[1])] = $ContactItem.$Key;
                        }

    to

                        "Email"
                        {
                            $Email1EmailAddress  = New-Object Microsoft.Exchange.WebServices.Data.ExtendedPropertyDefinition([Microsoft.Exchange.WebServices.Data.DefaultExtendedPropertySet]::Address,0x8083,[Microsoft.Exchange.WebServices.Data.MapiPropertyType]::String); 
                            $Email1AddressType  = New-Object Microsoft.Exchange.WebServices.Data.ExtendedPropertyDefinition([Microsoft.Exchange.WebServices.Data.DefaultExtendedPropertySet]::Address,0x8082,[Microsoft.Exchange.WebServices.Data.MapiPropertyType]::String); 
                            $Email1DisplayName  = New-Object Microsoft.Exchange.WebServices.Data.ExtendedPropertyDefinition([Microsoft.Exchange.WebServices.Data.DefaultExtendedPropertySet]::Address,0x8080,[Microsoft.Exchange.WebServices.Data.MapiPropertyType]::String); 
                            $Email1OriginalDisplayName  = New-Object Microsoft.Exchange.WebServices.Data.ExtendedPropertyDefinition([Microsoft.Exchange.WebServices.Data.DefaultExtendedPropertySet]::Address,0x8084,[Microsoft.Exchange.WebServices.Data.MapiPropertyType]::String); 
                            $ExchangeContact.SetExtendedProperty($Email1EmailAddress,$ContactItem.$Key)
                            $ExchangeContact.SetExtendedProperty($Email1AddressType,"SMTP")
                            $ExchangeContact.SetExtendedProperty($Email1DisplayName,$ContactItem.$Key)
                            $ExchangeContact.SetExtendedProperty($Email1OriginalDisplayName,$ContactItem.$Key)
                        }
    Cheers
    Glen

    • Marked as answer by Russell Wong Tuesday, December 13, 2016 7:00 AM
    Tuesday, December 13, 2016 4:38 AM

All replies

  • Hi @KHart85 thank you for replying but that is a solution for something completely different altogether. Steven Goodman's script is to import contacts into a users personal account. That is what I'm looking for. Just to import from .csv to a user's personal account in O365 but to do that in batches. Please let me know if you can take a look at Steven Goodman's powershell script to modify the code. Cheers!
    Monday, December 12, 2016 1:44 AM
  • You need to set the extended properties rather then the strongly typed one to stop is resolving the address from the Gal eg try changing

                        "Email"
                        {
                            $ExchangeContact.EmailAddresses[[Microsoft.Exchange.WebServices.Data.EmailAddressKey]::($MappingArray[1])] = $ContactItem.$Key;
                        }

    to

                        "Email"
                        {
                            $Email1EmailAddress  = New-Object Microsoft.Exchange.WebServices.Data.ExtendedPropertyDefinition([Microsoft.Exchange.WebServices.Data.DefaultExtendedPropertySet]::Address,0x8083,[Microsoft.Exchange.WebServices.Data.MapiPropertyType]::String); 
                            $Email1AddressType  = New-Object Microsoft.Exchange.WebServices.Data.ExtendedPropertyDefinition([Microsoft.Exchange.WebServices.Data.DefaultExtendedPropertySet]::Address,0x8082,[Microsoft.Exchange.WebServices.Data.MapiPropertyType]::String); 
                            $Email1DisplayName  = New-Object Microsoft.Exchange.WebServices.Data.ExtendedPropertyDefinition([Microsoft.Exchange.WebServices.Data.DefaultExtendedPropertySet]::Address,0x8080,[Microsoft.Exchange.WebServices.Data.MapiPropertyType]::String); 
                            $Email1OriginalDisplayName  = New-Object Microsoft.Exchange.WebServices.Data.ExtendedPropertyDefinition([Microsoft.Exchange.WebServices.Data.DefaultExtendedPropertySet]::Address,0x8084,[Microsoft.Exchange.WebServices.Data.MapiPropertyType]::String); 
                            $ExchangeContact.SetExtendedProperty($Email1EmailAddress,$ContactItem.$Key)
                            $ExchangeContact.SetExtendedProperty($Email1AddressType,"SMTP")
                            $ExchangeContact.SetExtendedProperty($Email1DisplayName,$ContactItem.$Key)
                            $ExchangeContact.SetExtendedProperty($Email1OriginalDisplayName,$ContactItem.$Key)
                        }
    Cheers
    Glen

    • Marked as answer by Russell Wong Tuesday, December 13, 2016 7:00 AM
    Tuesday, December 13, 2016 4:38 AM
  • You need to set the extended properties rather then the strongly typed one to stop is resolving the address from the Gal eg try changing

                        "Email"
                        {
                            $ExchangeContact.EmailAddresses[[Microsoft.Exchange.WebServices.Data.EmailAddressKey]::($MappingArray[1])] = $ContactItem.$Key;
                        }

    to

                        "Email"
                        {
                            $Email1EmailAddress  = New-Object Microsoft.Exchange.WebServices.Data.ExtendedPropertyDefinition([Microsoft.Exchange.WebServices.Data.DefaultExtendedPropertySet]::Address,0x8083,[Microsoft.Exchange.WebServices.Data.MapiPropertyType]::String); 
                            $Email1AddressType  = New-Object Microsoft.Exchange.WebServices.Data.ExtendedPropertyDefinition([Microsoft.Exchange.WebServices.Data.DefaultExtendedPropertySet]::Address,0x8082,[Microsoft.Exchange.WebServices.Data.MapiPropertyType]::String); 
                            $Email1DisplayName  = New-Object Microsoft.Exchange.WebServices.Data.ExtendedPropertyDefinition([Microsoft.Exchange.WebServices.Data.DefaultExtendedPropertySet]::Address,0x8080,[Microsoft.Exchange.WebServices.Data.MapiPropertyType]::String); 
                            $Email1OriginalDisplayName  = New-Object Microsoft.Exchange.WebServices.Data.ExtendedPropertyDefinition([Microsoft.Exchange.WebServices.Data.DefaultExtendedPropertySet]::Address,0x8084,[Microsoft.Exchange.WebServices.Data.MapiPropertyType]::String); 
                            $ExchangeContact.SetExtendedProperty($Email1EmailAddress,$ContactItem.$Key)
                            $ExchangeContact.SetExtendedProperty($Email1AddressType,"SMTP")
                            $ExchangeContact.SetExtendedProperty($Email1DisplayName,$ContactItem.$Key)
                            $ExchangeContact.SetExtendedProperty($Email1OriginalDisplayName,$ContactItem.$Key)
                        }
    Cheers
    Glen

    Thank you so much Glen, that works fantastically. I'm just figuring out how to have the email address display in the output part though. After using your suggested changes, the EmailAddress column is blank.

    Very much appreciated so far! Thank you!

    Russell W.

    Tuesday, December 13, 2016 6:59 AM
  • I don't quite get what he's doing here is it just for reporting ?

        # Provide output that can be used on the pipeline
        $Output_Object = New-Object Object;
        $Output_Object | Add-Member NoteProperty FileAs $ExchangeContact.FileAs;
        $Output_Object | Add-Member NoteProperty GivenName $ExchangeContact.GivenName;
        $Output_Object | Add-Member NoteProperty Surname $ExchangeContact.Surname;
        $Output_Object | Add-Member NoteProperty EmailAddress1 $ExchangeContact.EmailAddresses[[Microsoft.Exchange.WebServices.Data.EmailAddressKey]::EmailAddress1]
        $Output_Object;

    if put a Load in after save that should refresh the Contacts properties which should then populate that property eg find the line

     $ExchangeContact.Save();

    and add a Load after it eg

    $ExchangeContact.Save();
    $ExchangeContact.Load();

    Cheers
    Glen

    Wednesday, December 14, 2016 1:57 AM