Import contacts from csv to specified folder RRS feed

  • Question

  • I am looking to import contacts from a csv file into a subfolder of an office365 user. So far, this is what I have:

    Import-ContactList -CSV -CSVData ([System.IO.File]::ReadAllBytes("C:\file.csv")) -Identity username@domain.org

    This will import into the users Contacts, however I am trying to target a subfolder under contacts. Is anyone aware of a way to specify that?

    Wednesday, March 22, 2017 7:51 PM

All replies

  • The cmdlet does not support specifying folders, so instead you can use some EWS based script such as the one here: http://www.stevieg.org/2010/07/using-powershell-to-import-contacts-into-exchange-and-outlook-live/
    • Proposed as answer by David Wang_ Thursday, March 23, 2017 2:43 AM
    Wednesday, March 22, 2017 8:13 PM
  • Thank you very much for your response and help!

    This seems to be a script relating to a 2010 Exchange server, not for Office365. It does look promising at first, but I think it may be referencing on prem server actions. Let me give you more info....

    We are in a hybrid environment, with public folders on prem that I have already configured to be accessible from a cloud user. One of our public folders is a contact folder which we use Code2 to access each users contact folder and dump the contacts from the public folder into their personal contacts. When we went to office 365, we were not able to bring this environment with us. Our answer to this was creating a script that created a contact folder under the default contact folder. Now we just need to be able to dump contacts into that folder. This is so our users can have contacts on their mobile devices (something Microsoft does not have an answer to at the moment).

    While the script seems promising, I think there are a few parts that need changing, and while I have tried, I may be missing something.

    1.  The line stated on 172 - Microsoft.Exchange.WebServices.Data.ContactsFolder]::Bind($service, [Microsoft.Exchange.WebServices.Data.WellKnownFolderName] is pointing to "WellKnownFolderName". I tried changing this to a subfolder, which is where we need it to go, however that didnt work.

    2. On line 134 I changed the service object to Exchange2013 to more likely match what is going on in the cloud. This worked for another script we have, but again, I dont know if it applies here.

    3. On line 121 I changed the $EWSManagedApiDLLFilePath to "https://outlook.office365.com/EWS/Exchange.asmx". This is so it points to the cloud instead of an on prem server. 

    The only thing we are looking to do here is to upload contacts in a subfolder under the contacts container that we already have created for each user - we have managed to create them in the contact folder itself, but at that point they cannot be managed. The kicker is doing that in office365. I think this script would absolutely work for an on prem server.

    Doug A

    Thursday, March 23, 2017 12:05 PM
  • You never mentioned PFs, but if you have the contacts exported to CSV file, it doesn't make a difference. The script should work just fine in O365 too (after changing the EWS endpoint).

    To bind to a non-default folder, you need to search for it first. Glen has a nice article on the subject here: http://gsexdev.blogspot.bg/2012/01/ews-managed-api-and-powershell-how-to_23.html

    Thursday, March 23, 2017 1:01 PM
  • What if we know the non-default folder name? Can we specify it in the line below by adding parameters to Contacts?

     $ContactsFolder = [Microsoft.Exchange.WebServices.Data.ContactsFolder]::Bind($service, [Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::Contacts)

    Doug A

    Thursday, March 23, 2017 2:29 PM
  • You can try, and fail, and use the example in Glen's article :)
    Thursday, March 23, 2017 2:57 PM
  • Hi, I'm trying to do the same thing.
    Did you find a solution?

    Thanks :)
    Saturday, February 23, 2019 9:43 PM