Jump to content

Recommended Posts

Posted

Hi There,

 

I have been asked to create 582 External contacts in office 365. Once i have created the contacts in office 365 i will then move them to a group so the headteacher can email everyone at once.

 

I know this can be done using powershell but I can't seem to get it right. If there any powershell wizards on here that can help me to import the contacts via CSV file onto office 365.

 

P.S - I have already created the CSV File with 2 contacts to test for the time being and i have he required fields. "ExternalEmailAddress" , "Name" , "FirstName" , "Last Name"

 

Thank-you in advance.

Posted
Could you post up the script you are using or let us know of any error messages you are getting? :)

 

Thanks for the reply Matt_Renato

 

I am not very good at doing powershell scripts yet but i am trying to learn. This one i am trying to do is the biggest one i have done so far. I have learned how to create groups and delete users using powershell but can't seem to figure out this one.

 

please see attached image of my script so far. External Contacts Script.JPG

Posted

The script below should work, give it a test with a couple of users and let me know if you run into any problems.

 

### Get Office 365 Login Credentials
$Credential = Get-Credential


### Setup connection with entered Credentials
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $Credential -Authentication Basic -AllowRedirection


### Connect to Exchange Online
Import-PSSession $Session

### Path to CSV file
$CSVFile = "C:\Temp\ContactImport.csv"


### Import the users from the CSV file
Import-Csv $CSVFile | ForEach {New-MailContact -Name $_.Name -DisplayName $_.Name -ExternalEmailAddress $_.ExternalEmailAddress -FirstName $_.FirstName -LastName $_.LastName}


### Disconnect the Exchange Online session
Remove-PSSession $Session

 

You need to connect to Exchange Online in order to create the contacts, as you can see it's slightly more complex than connecting to Azure Active Directory which is where your Office 365 users are located and can be accessed from Powershell using Connect-MsolService.

 

You will need to set the $CSVFile variable to the path of the CSV file containing the users you wish to import. I prefer to do things this way as there is less risk of accidentally editing the main code if you need to make a change to the path in the future.

 

Finally the columns in your CSV file will need to be named as follows Name, ExternalEmailAddress, FirstName, LastName

 

If you have any further questions then feel free to ask away.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...