I got a request a few months ago for a script to monitor a couple of AD groups. The requirements were an excel sheet which contained the Users Name, ID# and Group Name so the sheet could be filtered and sorted.
Note: This script requires the ActiveRoles Management Shell for Active Directory.
Connect-QADService $Results = @() $Date = (Get-Date -DisplayHint Date) $save_date = $Date.ToString("MM-dd-yyyy") $Groups = "First_ADGroup","Second_ADGroup" $Groups = $Groups | Get-QADGroup foreach($group in $Groups){ foreach($user in $group) { $Results += Get-QADGroupMember $user -Indirect -SizeLimit 0 | Add-Member -Name "Users" -value $user -MemberType NoteProperty -PassThru | Add-Member -Name "Group" -value $group -MemberType NoteProperty -PassThru | Select DisplayName,SamAccountName,Group } } $file_output = ('D:\Path_To_Save_File\File-' + $save_date + '.csv') $Results | Export-CSV -Path $file_output -NoTypeInformation Start-Sleep -s 20 $filename = $file_output $smtpServer = “SMTP Server or SMTP Relay Server” $msg = new-object Net.Mail.MailMessage $att = new-object Net.Mail.Attachment($filename) $smtp = new-object Net.Mail.SmtpClient($smtpServer) $msg.From = “yourname@whatever.com” $msg.To.Add(”User you want to send this to”) $msg.cc.Add("Add a cc address or comment this line out") $msg.Subject = “Weekly AD Group Membership Tracking" $msg.Body = “E-mail body message” $msg.Attachments.Add($att) $smtp.Send($msg)