Mail Enable all Groups in a Specified OU

Mail Enable all Active Directory Groups in a Specified OU

I wrote up the following script to support a System Center 2012 R2 Service Manager deployment. A series of Security Groups were used to support user roles and workflows within Service Manager, however these groups were not originally mail enabled. Luckily, all of the groups resided in the same OU, called "Service Manager", so mail enabling the lot was pretty simple. 

The following can be executed from the Exchange Shell.
Make sure you modify the SearchBase and Domain names to match your environment.

# Mail Enable all Groups in the Specified OU, ensuring SMTP Address matches the DisplayName, excluding any spaces.
$Groups = Get-ADGroup -SearchBase "OU=Service Manager Groups,OU=TenIT,DC=TenIT,DC=us" -Filer *

ForEach ($Group in $Groups)
    Enable-DistributionGroup -Identity $Group.DistinguishedName -PrimarySMTP (($Group.DisplayName -replace '\s+', "") + '')


Modify the following:

  1. "OU=Service Manager Groups,OU=TenIT,DC=TenIT,DC=us"
  2. ''