Hello
I have a Powershell script I have working fine but I have to send an automatic email by a task scheduler via 2008 server to all managedby (owner of group) to several different group with a text of each memberlist. In my $messagebody1 - I would like to add the group name of each group that correspondes to each $messagessubject .
Example: When I run the script it will send an email to the manageredby (owner) with the memberlist listed in a text in the email. I have listed the script below and an email example: Please read the second line in the $messagebody1 that starts with The following users listed “”“”
#GroupOwnerEmail.ps1
#Prupose: Pull AD groups from grouplist, get member attributes and smtp mail to group owner for review
$smtpServer = “”
$smtpFrom = “”
$messagebody1 = "This message is notice for the quarterly group membership attestation required by our Policies.
The following users listed below are members of the ($group) group, which provides privileged access to AIX servers.
You are listed as the Custodian of this group. Please verify these users should retain this access.
If any users should be removed, please submit a Service Now Revoke Access request.
Please reply to this email, affirming that you have reviewed the access to this group.
If you are no longer the custodian, please reply stating so.
If known, please also provide the name of the person now managing this group’s members
Thank you"
$groups = Get-Content c:\temp\adgroups.txt
[string]$messagebody = “”
foreach ($group in $groups)
{
$group = Get-QADGroup $group
$ManagedBy = (Get-QADUser $Group.ManagedBy).Email
$smtpTo = $managedby
$messagebody2 = Get-QADGroupMember $group | % {
“r
nr
n”
“$($.NTaccountName.ToString())", " “,”$($.DisplayName.ToString())”," “,”$($_.Email.ToString())"
}
$smtp = New-Object Net.Mail.SmtpClient($smtpServer)
$messageSubject = “Action Required - Review Members List For group " + " $Group - 4th Quarter”
$smtp.Send($smtpFrom,$smtpTo,$messagesubject,$messagebody1 + $messagebody2)
}
Here is the email that’s generated:
-----Original Message-----
From: MyEmail
Sent: Monday, October 14, 2013 9:38 AM
To: MyEmail
Subject: Action Required - Review Members List For Group (GroupName works fine) - 4th Quarter
This message is notice for the quarterly group membership attestation required by our Policies.
The following users are members of the (GroupName) group, which provides privileged access to AIX servers.
You are listed as the Custodian of this group. Please verify these users should retain this access.
If any users should be removed, please submit a Service Now Revoke Access request.
Please reply to this email, affirming that you have reviewed the access to this group.
If you are no longer the custodian, please reply stating so.
If known, please also provide the name of the person now managing this group’s members
Thank you
Userid John Bob1 jbob1@mydomain.com
Userid John Bob2 jbob2@mydomain.com
Userid John Bob3 jbob3@mydomain.com
Userid John Bob4 jbob4@mydomain.com
I have four different group with four different manageredby to receive individaul email with their group lasted in the $messagebody1. The subject is working correctly - it will listed the different group names per a text file - $groups = Get-Content c:\temp\adgroups.txt.
Thank you