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).
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 firstname.lastname@example.org -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
Or to go looking through the SIP handle you should utilize
(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
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
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
to create a contact and add a contact image
to create a contact in a person created subfolder
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
Instance 2 replace the telephone variety of a contact in a customers subfolder
Replace-Contact -Mailboxname email@example.com -EmailAddress contactEmai@area.com -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
to delete a contact from a non person subfolder
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
If the file already exists it should deal with creating a novel filename
To export from a contacts subfolder use
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
Instance 2 to save lots of a GAL Entry to vcf together with the customers picture
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
Instance 2 Copy a GAL contact to a Contacts subfolder