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")
}
ago by (1.2k points)

1 Answer

ago by (306k points)
+1 vote

Hello,

The proper approach in this case is to use your script in the business rule condition (the script will require corresponding updates) and the Send this operation for approval action. The rule will look like the following: image.png If you still prefer adding the approval part to the script, use method $Context.SubmitForApproval.

Related questions

In a business rule, I'd like to pass Adaxes variables into a powershell script that I'll run. For example, pass %username% into the script so it can be used inside the script.

asked Sep 5, 2024 by P-Sysadmin (20 points)
0 votes
1 answer

I haven't seen a version to know the syntax.

asked 1 day ago by mightycabal (1.2k points)
0 votes
1 answer

Occationally Service Desk staff need to clear a DNS record when a desktop has been reimaged but is keeping the same name as loses the ability to manage its original DNS ... running in ADAXES. Can I just install the applet on the ADAXES server using powershell?

asked Jan 17, 2023 by stevehalvorson (150 points)
0 votes
1 answer

Recently, Microsoft deprecated use of the remote PS sessions using version 1. We have since converted all of our scripts to version 2, but our nightly staff ... { # Close the remote session and release resources Disconnect-ExchangeOnline -Confirm:$false }

asked Nov 2, 2022 by MShep (80 points)
0 votes
1 answer

I'm in the process of creating a Web interface for requesting IT accounts. Upon submission, I want to run a Powershell script that will create an item in a Sharepoint task list.

asked May 14, 2021 by sandramnc (870 points)
0 votes
1 answer