EWS Contacts rollup Powershell module

EWS Contacts rollup Powershell module On this put up I will attempt to rollup numerous completely different Contact Scripts I’ve posted over the previous couple of years into one module that may hopefully make issues just a little simpler to make use of once you need to do issues with Contacts utilizing EWS and Powershell

I’ve put the code for this script up in GitHub repo https://github.com/gscales/Powershell-Scripts/blob/grasp/EWSContacts/EWSContactFunctions.ps1 it is 1K+ strains and I hope so as to add a number of extra issues to the script as I am going (and repair bugs). But when anyone has concept’s please use GitHub to submit them. You may download the script as a zipper from right here

So here is what it could possibly do for the time being


This can be utilized to get a Contact from the Mailbox’s default contacts folder, different contacts sub folder or the World Tackle Record eg to get a contact from the default contact folder by looking utilizing the E mail Tackle (This can return a EWS Managed API Contact object).

Instance 1

Get-Contact -MailboxName [email protected] -EmailAddress [email protected] mail.com

This can search the default contacts folder utilizing the ResolveName operation in EWS, it additionally caters for contacts that the place added from the World Tackle Record in Outlook. Whenever you add a contact from the GAL the e-mail handle that’s saved within the Mailbox’s contacts Folder makes use of the EX Tackle format. So on this case once you go to resolve or search on the SMTP handle it will not discover the contact that has been added from the GAL with this handle. To cater for this the GAL can also be looked for the EmailAddress you enter in (utilizing ResolveName), if a GAL entry is returned (that has an identical EmailAddress) then the EX Tackle is obtained utilizing Autodiscover and the UserDN property after which one other Resolve is completed in opposition to the Contacts Folder utilizing the EX handle.

As a result of ResolveName means that you can resolve in opposition to extra then simply the E mail handle I’ve added a -Partial Swap so you can too do partial match searches. Eg to return all of the contacts that include a specific phrase (word this may very well be throughout all of the properties which are searched) you should utilize

Get-Contact -MailboxName [email protected] -EmailAddress glen -Partial

By default solely the Main E mail of a contact is checked once you utilizing ResolveName in order for you it to go looking the multivalued Proxyaddressses property that you must use one thing like the next

Get-Contact -MailboxName  [email protected] -EmailAddress smtp:[email protected] -Partial

Or to go looking through the SIP handle you should utilize

Get-Contact -MailboxName  [email protected] -EmailAddress sip:[email protected] -Partial

(utilizing the Partial change is required on this case as a result of the EmailAddress your search on will not match the PrimaryAddress of the contact so on this case additionally you may get partial matches again).

There’s additionally a -SearchGal change for this cmdlet which implies solely the GAL is searched eg

Get-Contact -MailboxName [email protected] -EmailAddress [email protected] -SearchGal

On this case the contact object returned will probably be learn solely (though it can save you it right into a contacts folder which I’ve utilized in one other cmdlet).

Lastly in case your contacts aren’t situated within the default contacts folder you possibly can use the folder parameter to enter within the path to folder that you really want to go looking eg

Get-Contact -MailboxName [email protected] -EmailAddress [email protected] -Folder “ContactsSubFolder”


This can be utilized to create a contact, I’ve added parameters for all the commonest properties you’ll set in a contact, some contact property must be set through Prolonged properties (if that you must set this you possibly can both add it in your self or after you create the contact use Get-Contact and replace the contact object).

Instance 1 to create a contact within the default contacts folder

Create-Contact -Mailboxname [email protected] -EmailAddress [email protected] -FirstName John -LastName Doe -DisplayName “John Doe”

to create a contact and add a contact image

Create-Contact -Mailboxname [email protected] -EmailAddress [email protected] -FirstName John -LastName Doe -DisplayName “John Doe” -photo ‘c:photoJdoe.jpg’

to create a contact in a person created subfolder

 Create-Contact -Mailboxname [email protected] -EmailAddress [email protected] -FirstName John -LastName Doe -DisplayName “John Doe” -Folder “MyCustomContacts”

This cmdlet makes use of the EmailAddress as distinctive key so it wont allow you to create a contact with that electronic mail handle if one already exists.


This Cmdlet can be utilized to replace an present contact the Main electronic mail handle is used as a novel key so that is the one property you possibly can’t replace. It should take the Partial change like the opposite cmdlet however will all the time immediate earlier than updating on this case.

Example1 replace the telephone variety of an present contact

Replace-Contact  -Mailboxname [email protected] -EmailAddress [email protected] -MobilePhone 023213421

Instance 2 replace the telephone variety of a contact in a customers subfolder

Replace-Contact  -Mailboxname [email protected] -EmailAddress [email protected] -MobilePhone 023213421 -Folder “MyCustomContacts”


This Cmdlet can be utilized to delete a contact from a contact folders

eg to delete a contact from the default contacts folder

Delete-Contact -MailboxName [email protected] -EmailAddress electronic [email protected]

to delete a contact from a non person subfolder

Delete-Contact -MailboxName [email protected] -EmailAddress electronic [email protected] -Folder ContactsSubfolder


This cmdlet can be utilized to export a contact to a VCF file, this takes benefit of EWS potential to supply the contact as a VCF stream through the MimeContent property.

To export a Contact to a vcf use

Export-Contact -MailboxName [email protected] -EmailAddress [email protected] -FileName c:exportfilename.vcf

If the file already exists it should deal with creating a novel filename

To export from a contacts subfolder use

Export-Contact -MailboxName [email protected] -EmailAddress [email protected] -FileName c:exportfilename.vcf -folder contactssubfolder


This cmdlet exports a World Tackle Record entry to a VCF file, in contrast to the Export-Contact cmdlet which may benefit from the MimeStream supplied by the Alternate Retailer with GAL Contact you do not have this out there. The script creates aVCF file manually utilizing the properties returned from ResolveName. By default the GAL picture is included with the file however I’ve included a -IncludePhoto change which can use the GetUserPhoto operation which is simply out there on 2013 and higher.

Instance 1 to save lots of a GAL Entry to a vcf

Export-GalContact -MailboxName [email protected] -EmailAddress electronic [email protected] -FileName c:exportexport.vcf

Instance 2 to save lots of a GAL Entry to vcf together with the customers picture

Export-GalContact -MailboxName [email protected] -EmailAddress electronic [email protected] -FileName c:exportexport.vcf -IncludePhoto


This Cmdlet copies a contact from the World Tackle listing to an area contacts folder. The EmailAddress in used as a novel key so the identical contact will not be copied into an area contacts folder if it already exists. By default the GAL picture is not included however I’ve included a -IncludePhoto change which can use the GetUserPhoto operation which is simply out there on 2013 and higher.

Instance 1 to Copy a Gal contacts to native Contacts folder

Copy-Contacts.GalToMailbox -MailboxName [email protected] -EmailAddress electronic [email protected]

Instance 2 Copy a GAL contact to a Contacts subfolder

Copy-Contacts.GalToMailbox -MailboxName [email protected] -EmailAddress electronic [email protected]  -Folder ContactsUnderContacts


Rate this article!

Related Posts

Leave a Reply