Windows Management User Group

Create External Contacts with CSV and PowerShell

By Michel van Vliet

To create External Contacts in Office 365/Exchange Online I’ve created a script which uses a CSV file for input. The file must be saved as “Unicode, Semicolon separated” (;) and must contain the following fields:

Name
Description
ExternalEmailAddress
Email Address for the contact (this filed cannot contain spaces!)
Name
Full / Display Name
FirstName
First name
LastName
Last name
StreetAddress
Street Address
City
City
StateorProvince
State or Province
PostalCode
ZIP or Postal Code
Phone
Office Phone
MobilePhone
Mobile Phone
Pager
Fax
HomePhone
Address
Company
City
Title
State or Province
Department
ZIP or Postal Code
CountryOrRegion
Country or Region
Fax
Fax
Initials
Initials
Notes
Notes
Office
Office
Manager
Manager
Hidden
Hide or show the contact in the Global Address List with this field.It can contain only two values: TRUE or FALSE. When using TRUE the contact is hidden. If this field is left blank, the contact is made visible (=TRUE).

Script

Here’s the code for the script:

#### Create Function Logon to Office365 – Exchange Online
function Logon {
#### Pop-up a dialog for username and request your password
$cred = Get-Credential
#### Import the Local Microsoft Online PowerShell Module Cmdlets and Connect to O365 Online
Import-Module MSOnline
Connect-MsolService -Credential $cred
#### Establish an Remote PowerShell Session to Exchange Online
$msoExchangeURL = “https://ps.outlook.com/powershell/”
$session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri $msoExchangeURL -Credential $cred -Authentication Basic -AllowRedirection
…read more

Read more here:: Techready