Sure thing!
Example CSV I am looking for:
Below is my current script (Some data has been changed to example data):
# Group Membership Report Begin
$csvFilePath = "C:\exampleFolder\%name%_MembershipReport.csv" # TODO: Modify me
$now = [System.DateTime]::Now.ToString("yyyy.MM.dd.HH.mm.ss")
$csvFilePath = [System.String]::Format($csvFilePath, $now)
# Get group members
try
{
$memberGuidsBytes = $Context.TargetObject.GetEx("adm-MembersGuid")
}
catch
{
}
# Build report
$report = @()
foreach ($memberGuidBytes in $memberGuidsBytes)
{
# Bind to the group member
$memberGuid = New-Object "System.Guid" (, $memberGuidBytes)
$memberGuid = $memberGuid.ToString("B")
$memberPath = "Adaxes://<GUID=$memberGuid>"
$member = $Context.BindToObject($memberPath)
# Add member information to the report
$memberName = [Softerra.Adaxes.Utils.ObjectNameHelper]::GetObjectName($member, 'IncludeParentPath')
if ($Context.TargetObject.IsMember($memberPath))
{
$membershipType = "Direct"
}
else
{
$membershipType = "Indirect"
}
$memberClass = $member.Class
$reportEntry = New-Object PSObject
$reportEntry | Add-Member -Name Name -Value $memberName -MemberType NoteProperty
$reportEntry | Add-Member -Name Class -Value $memberClass -MemberType NoteProperty
$reportEntry | Add-Member -Name "Membership Type" -Value $membershipType -MemberType NoteProperty
$report += $reportEntry
}
# Export report to CSV
$report | Export-Csv -Path $csvFilePath -NoTypeInformation
# Group Membership Report End
# Group MemberOf Report Begin
# Group MemberOf Report End
# HTML Email Template
$nowdate = [System.DateTime]::Now.ToString("dddd, MMMM dd yyyy")
$nowtime = Get-Date -Format t
$EmailBody = @"
<div style="width: 50%%; display: block; margin-left: auto; margin-right: auto">
<table style="width: 100%%; border-collapse: collapse; border: 1px solid #202945">
<tr>
<td colspan="2" bgcolor="#202945" style="color: #FFFFFF; font-size: large; text-align: center; height: 100px;">
Security Group Deleted: %cn% <br/> $nowdate at $nowtime
</td>
</tr>
<tr style="border-bottom-style: solid; border-bottom-width: 1px; padding-bottom: 1px">
<td style="width:120px; height: 50px; padding: 10px"> <b>Initiator:</b></td>
<td style="text-align: left; height: 35px">
%adm-InitiatorFullName% (%adm-InitiatorUserName%)</td>
</tr>
<tr style="border-bottom-style: solid; border-bottom-width: 1px; padding-bottom: 1px">
<td style="width:120px; height: 50px; padding: 10px"> <b>Full Operation:</b></td>
<td style="text-align: left; height: 50px">
%adm-OperationDescription%</td>
</tr>
<tr style="height: 50px">
<td style="width: 120px; height: 50px; padding: 10px"> <b>Members:</b></td>
<td style="text-align: left; height: 50px">
Please see the attached membership report. If the security group contains no members then an empty CSV file will be included.</td>
</tr>
</tr>
<tr style="height: 50px">
<td style="width: 120px; height: 50px; padding: 10px"> <b>Member Of:</b></td>
<td style="text-align: left; height: 50px">
Please see the attached MemberOf report. If the security group is not a member of any groups an empty CSV file will be included.</td>
</tr>
</table>
</div>
"@
# Send Email
$emails = "exampleEmail@domain.com"
Start-Sleep -s 15
Send-MailMessage -From "example@domain.com" -To $emails -Subject 'Adaxes: Security Group Deleted - %cn%' -Body $EmailBody -BodyAsHtml -Attachments $csvFilePath -Priority High -DeliveryNotificationOption OnSuccess, OnFailure -SmtpServer 'exampleSmtpServer.domain.com'
Start-Sleep -s 5
Remove-Item -path $csvFilePath