I am creating a script triggered by a buisness rule. The rule is triggered 'before createing a user' This script checks for a duplicate user. If the script finds a duplicate, I want to send the creation operation to be approved. I'm hoping I can script that and add it to my script.
# Get possible duplicates by DisplayName
$duplicates = Get-AdmUser -Filter { displayName -eq "%lastname%,%firstname%"} `
-Properties samAccountName, givenName, sn, initials
if ($duplicates) {
# Build a simple HTML table
$rows = $duplicates | ForEach-Object {
"<tr><td>$($_.samAccountName)</td><td>$($_.givenName)</td><td>$($_.sn)</td><td>$($_.initials)</td></tr>"
} | Out-String
$Body = @"
<html>
<head>
<style>
table { border-collapse: collapse; font-family: Segoe UI, Arial; font-size: 12px; }
th, td { border: 1px solid #ccc; padding: 4px 6px; text-align: left; }
th { background: #f0f0f0; }
</style>
</head>
<body>
<p><b>Duplicate DisplayName detected:</b> %displayName%</p>
<p><b>New user:</b> %samAccountName%</p>
<table>
<tr>
<th>samAccountName</th>
<th>First Name</th>
<th>Last Name</th>
<th>Initials</th>
</tr>
$rows
</table>
</body>
</html>
"@
#Prod
#$To = 'Someemail@test.com'
#QA
$To = 'Someemail@test.com'
$Sub = "Duplicate check: %displayName%"
$Context.SendMail($To, $Sub, $NULL, $Body)
$Context.LogMessage("Duplicate check: notification sent for %displayName%","Information")
}
else {
$Context.LogMessage("Duplicate check: no duplicates found for %displayName%","Information")
}