Thursday, September 24, 2015

Creating and modifying Contact Groups with EWS and Powershell

Mailbox Contact Groups have been around for a while and while there are a number of other Group options in Exchange from a users point of view these are still one of the most efficient ways of creating Distribution groups. I've updated my EWS PowerShell Contacts module to support creating and modifying Contact Groups. So using this module you can now

Create a ContactGroup in the default contacts folder of a Mailbox

Create-ContactGroup -Mailboxname mailbox@domain.com -GroupName GroupName -Members ("member1@domain.com","member2@domain.com")

Add more Members to that Group

$Group = Get-ContactGroup -Mailboxname mailbox@domain.com -GroupName GroupName $Group.Members.Add("newMember@domain.com")
$Group.Update(0)

This was just using the generic Add method but there are a number of methods for adding different types of contacts such as MailEnalbed Public Folders,ContactGroups,Directory Users etc see https://msdn.microsoft.com/en-us/library/office/microsoft.exchange.webservices.data.groupmembercollection_methods%28v=exchg.80%29.aspx

Delete the Group
$Group = Get-ContactGroup -Mailboxname mailbox@domain.com -GroupName GroupName
$Group.Delete(2)

 The Contacts Module is up on GitHub https://github.com/gscales/Powershell-Scripts/tree/master/EWSContacts you can download a zip from here