Sometimes you need to email everyone in an AD Group. Instead of managing a separate mailing list in Outlook, you can grab the addresses directly from AD.
####################################################################################################
# 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()