Powershell script to bulk import external contacts into M365
Posted by jbruff@reddit | sysadmin | View on Reddit | 20 comments
Im trying to import 500 external email contacts into M365. I havent had to use powershell in 10 years. Im not sure where im getting things wrong on this. Ive created the CSV in excel, the headers at the top of the dock are Name, Phone and ExternalEmailAddress in that order. From what im seeing this is needlessly complicated or im just hella outdated lol. When i remote in i get this error when i try to import the list.
Import-Csv: Cannot bind parameter 'Delimiter'. Cannot convert value "Documents/com\\~apple\\~CloudDocs/WIP/ParentContact.csv" to type "System.Char". Error: "String must be exactly one character long."
What am i doing wrong?
worldsdream@reddit
This post helped tremendously with importing external contacts. Great scripts and explanation:
https://o365info.com/bulk-import-contacts-microsoft-365-powershell/
TitsGiraffe@reddit
https://support.microsoft.com/en-au/office/import-contacts-to-outlook-for-windows-bb796340-b58a-46c1-90c7-b549b8f3c5f8#ID0EBBF=Classic_Outlook
Just do this with your CSV mate, it will flow through to all the other 365 apps. I used Powershell to hook into Graph and made a CSV of all our client's phone numbers to import so Teams caller ID would work for me.
Broad-Celebration-@reddit
365 allows you to just use the cloud gui to mass import contacts, no? Probably much less of a hassle.
jbruff@reddit (OP)
There isn't a gui way from what I've seen to read about.
Broad-Celebration-@reddit
I think it's admin center -> contacts -> add contact -> "add multiple" . I have not used it in a while so I may be off on some specifics. But I do know importing a contact list is available from the 365 admin center.
tmontney@reddit
That or the Azure portal. It has you download a template, which you then add your contacts, then upload.
Linedriver@reddit
Are you trying to use Import-CSV with a cloud file? Most of the import commands only work with paths mapped with windows file system.
jbruff@reddit (OP)
The file is local but in one of my icloud folders.
Linedriver@reddit
I can't be certain without looking at your script but it's looking like the file path is being used as -delimiter instead of -path.
jbruff@reddit (OP)
Im not using a script. this looked like its a simple command. I created the file in excel, saved it as a csv. this is the command i used:
import-csv /Users/actual/Library/Mobile\ Documents/com\\~apple\\~CloudDocs/WIP/ParentContact.csv
sitesurfer253@reddit
It's because you're flipping between forward and backslashes. Keep using forward slashes and you should be fine.
jbruff@reddit (OP)
I'm using a Mac, my local file systems requires the use of backslashes and delimiters due to file names. I'll move the local file to the drive root and try see if it'll upload from there.
sitesurfer253@reddit
Then surround the file path with quotations.
jbruff@reddit (OP)
imma just cheat and download windows and install it on UTM and us that to upload the file. I hate Windows but this seems like the most sure fire way to get this done. I'll experiment and figure out how to make it work from macOS natively when i dont have a time crunch.
Linedriver@reddit
You might have a blank space in there? ecause it's reading the Documents/com\\~apple ect as a -delimiter instead of being part of the file path.
jbruff@reddit (OP)
Im in a Mac, the file systems allow for spaces in file names, it uses a backslash to delimit it.
Linedriver@reddit
i'm not familir with powershell on mac but with windows it uses spaces to separate parts of the command so if you might need to wrap the whole file path in " " quotes if you need the blank space.
hihcadore@reddit
Where’s the rest of your script? Also r/powershell might be more helpful
BoltActionRifleman@reddit
I’m fairly new to 365 as we’ve just started migrating some accounts, but maybe the admin portal would have a way to just import a CSV?
AgentSuckMyBalls@reddit
Try using the -Delimiter parameter and specify a comma.