Sometimes you have to send an e-mail to members of an AD Group. This may be the case if you find it necessary to inform all your co-workers. If you administer the resource via Active Directory group you have the option to send an e-mail to all the group’s members. It’s best to go with the PowerShell script ‚CreateMailFromGroup‘.
Index
Send E-Mails to AD Group Members
The PowerShell script „CreateMailFromGroup.ps1“ reads all users of the AD transfer group recursively.
It reads the attribute “email” from all user accounts to find out all the group members’ addresses. So, in the end you want to send an e-mail via Outlook to all e-mail addresses. During this process it will enter all e-mail addresses as BBC (Blind Carbon Copy) in a new Outlook mail. If there is no parameter transferred the script queries the group.
Prequesitions for CreateMailFromGroup
It takes two conditions for the PS script to send an e-mail to all members of an AD Group. You have to install:
- MS Outlook
- ActiveDirectory module for PowerShell
PS-Script: E-Mail from AD Group
The script consists of different paragraphs, which the following part will explain more detailed. You find the complete script at the end of the article.
Querying Group
First it asks for a group and loads the Active Directory module.
1 2 3 4 5 6 |
param( [Parameter(Mandatory=$true)] [String]$Group ) Import-Module ActiveDirectory |
E-mail to members of an AD Group: Finding the Addresses
Next you find out the e-mail addresses with Get-ADGroupMember.
1 2 3 4 |
$EmailAddresses = Get-ADGroupMember $Group -Recursive | Get-ADUser -Properties mail | Select mail ForEach ($EmailAddress In $EmailAddresses){ $OLAddresses = $EmailAddress.mail + ";" + $OLAddresses } |
Sending the Outlook E-Mail to all Group Members
The last step is to assign Outlook as an e-mail client with New-Object. Outlook will then create a new e-mail address and set all addresses in the BCC.
1 2 3 4 5 |
$OL = New-Object -comObject Outlook.Application $Mail = $OL.CreateItem(0) $Mail.BCC = $OLAddresses $Mail.Display() |
Recommended article:
Complete PowerShell script: CreateMailFromGroup
Finally you have the complete script again. So you can send an e-mail to members of an AD Group.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
#################################################################################################### # CreateOLMailFromGroup.ps1 finds the e-mail addresses of all members of a group and creates an Outlook mail, it sets the e-mail addresses in the BCC. # # <span style="text-decoration: underline;">Prequesitions: Outlook and the feature "Active Directory module for Powershell" have to be</span> # installed #################################################################################################### # Query group param( [Parameter(Mandatory=$true)] [String]$Group ) # Load Active Directory module Import-Module ActiveDirectory # Find EMail addresses $EmailAddresses = Get-ADGroupMember $Group -Recursive | Get-ADUser -Properties mail | Select mail ForEach ($EmailAddress In $EmailAddresses){ $OLAddresses = $EmailAddress.mail + ";" + $OLAddresses } # Create Outlookmail $OL = New-Object -comObject Outlook.Application $Mail = $OL.CreateItem(0) #$Mail.TO = $OLAddresses $Mail.BCC = $OLAddresses $Mail.Display() |
Daily Procedure: Informing Group Members about Maintenance Measurements
It the IT wants to maintain a published application or a release. they can inform the respective users with the script exclusively. They can easily send an e-mail to members of an AD Group. By using the BCC the user can’t see other addressees.
Note:
However, you should care for the security regulations of the mail system. Probably the system may consider it spam. That is because there are so many e-mail addresses in the BCC.
FirstAttribute AG – Identity Management & IAM Cloud Services
We would be happy to present our services and solutions to you. Get in touch and find out how we can help you.
Leave a Reply
<p>Your email is safe with us.<br/>Information about our <a href="https://activedirectoryfaq.com/contact-us/">data protection policies</a></p>