We are looking for a way to (after creating account) check the number of groups associated with a user account and send an email if that number is 1 or less. We would like to use this as a check and balance to creating user accounts that may not be setup properly.

by (3.2k points)

1 Answer

by (306k points)
Best answer
0 votes

Hello,

Have a look at the following script from our repository: http://www.adaxes.com/script-repository ... r-s407.htm. If you have issues updating the script to meet your needs, we will help you.

by (3.2k points)
0

The Activity Scope shows nothing. I included the text as it appears in our script.

$to = "eca@aspendental.com" # TODO: modify me
$subject = "Adaxes Alert - group membership" # TODO: modify me
$reportHeader = "<b>Group membership</b><br/><br/>" # TODO: modify me
$reportFooter = "<hr /><p><i>Please do not reply to this e-mail, it has been sent to you for notification purposes only.</i></p>" # TODO: modify me

function SearchObjects($filter, $properties)
{
    $searcher = $Context.BindToObject("Adaxes://rootDSE")
    $searcher.SearchFilter = $filter
    $searcher.SearchScope = "ADS_SCOPE_SUBTREE"
    $searcher.PageSize = 500
    $searcher.ReferralChasing = "ADS_CHASE_REFERRALS_NEVER"
    $searcher.SetPropertiesToLoad($properties)
    $searcher.VirtualRoot = $True

    try
    {
        $searchResultIterator = $searcher.ExecuteSearch()
        $searchResults = $searchResultIterator.FetchAll()

        return ,$searchResults
    }
    finally
    {
        # Release resources
        if ($searchResultIterator){ $searchResultIterator.Dispose() }
    }
}

# Search users
$searchResults = SearchObjects "(sAMAccountType=805306368)" @("memberOf", "cn", "employeeID")

# Build report
$records = New-Object "System.Text.StringBuilder"
foreach ($searchResult in $searchResults)
{
    # Check user groups
    $values = $searchResult.Properties["memberOf"].Values

    if ($values.Count -gt 2)
    {
        continue
    }

    # Add user to report
    [void]$records.Append("<tr>")
    [void]$records.Append("<td>")
    [void]$records.Append($searchResult.Properties["cn"].Value)
    [void]$records.Append("</td>")
    [void]$records.Append("<td>")
    [void]$records.Append($searchResult.Properties["employeeID"].Value)
    [void]$records.Append("</td>")
    [void]$records.Append("</tr>")
}

# Build html
$html = New-Object "System.Text.StringBuilder"
[void]$html.Append($reportHeader)
if ($records.Length -eq 0)
{
    [void]$html.Append("<b>Users not found</b>")
}
else
{
    [void]$html.Append("<table border=""1"">")
    [void]$html.Append("<tr><th>Full Name</th><th>Employee ID</th></tr>")
    [void]$html.Append($records.ToString())
    [void]$html.Append("</table>")
}
[void]$html.Append($reportFooter)

# Send mail
$Context.SendMail($to, $subject, $NULL, $html.ToString())
by (306k points)
0

Hello,

As we can see, you have added the If located under condition to the Scheduled Task. Domains are not located under any OUs, thus the task does not get executed. Remove the condition and try running the script again.

If you need to include only users from a specific OU into the report, we will update the script for you.

by (3.2k points)
0

Yes we would want only the OU listed in the screenshot to be searched.

by (306k points)
0

Hello,

Thank you for clarifying. You need to create a Scheduled Task configured for Organizational Unit Object type. No conditions need be added to the task. To create the Scheduled Task:

  1. Launch Adaxes Administration Console.

  2. Right-click your Adaxes service node, navigate to New and click Scheduled Task.

  3. On step 3 of Create Scheduled Task wizard select Organizational-Unit Object type and click Next.

  4. Click Add Action and select Run a program or Powershell script.

  5. Enter a short description and paste the script below into the Script field. Do not change any lines in the script that do not have the TODO: Modify me comment.

     $to = "recipient@domain.com" # TODO: modify me
     $subject = "Group membership" # TODO: modify me
     $reportHeader = "<b>Group membership</b><br/><br/>" # TODO: modify me
     $reportFooter = "<hr /><p><i>Please do not reply to this e-mail, it has been sent to you for notification purposes only.</i></p>" # TODO: modify me
    
     function SearchObjects($filter, $properties)
     {
         $searcher = $Context.TargetObject
         $searcher.SearchFilter = $filter
         $searcher.SearchScope = "ADS_SCOPE_SUBTREE"
         $searcher.PageSize = 500
         $searcher.ReferralChasing = "ADS_CHASE_REFERRALS_NEVER"
         $searcher.SetPropertiesToLoad($properties)
    
         try
         {
             $searchResultIterator = $searcher.ExecuteSearch()
             $searchResults = $searchResultIterator.FetchAll()
    
             return ,$searchResults
         }
         finally
         {
             # Release resources
             if ($searchResultIterator){ $searchResultIterator.Dispose() }
         }
     }
    
     # Search users
     $searchResults = SearchObjects "(sAMAccountType=805306368)" @("memberOf", "cn", "employeeID")
    
     # Build report
     $records = New-Object "System.Text.StringBuilder"
     foreach ($searchResult in $searchResults)
     {
         # Check user groups
         $values = $searchResult.Properties["memberOf"].Values
    
         if ($values.Count -gt 1)
         {
             continue
         }
    
         # Add user to report
         [void]$records.Append("<tr>")
         [void]$records.Append("<td>")
         [void]$records.Append($searchResult.Properties["cn"].Value)
         [void]$records.Append("</td>")
         [void]$records.Append("<td>")
         [void]$records.Append($searchResult.Properties["employeeID"].Value)
         [void]$records.Append("</td>")
         [void]$records.Append("</tr>")
     }
    
     # Build html
     $html = New-Object "System.Text.StringBuilder"
     [void]$html.Append($reportHeader)
     if ($records.Length -eq 0)
     {
         [void]$html.Append("<b>Users not found</b>")
     }
     else
     {
         [void]$html.Append("<table border=""1"">")
         [void]$html.Append("<tr><th>Full Name</th><th>Employee ID</th></tr>")
         [void]$html.Append($records.ToString())
         [void]$html.Append("</table>")
     }
     [void]$html.Append($reportFooter)
    
     # Send mail
     $Context.SendMail($to, $subject, $NULL, $html.ToString())

  6. Click OK and then click Next.

  7. Click Add on the Activity Scope page and double-click the User Staging OU.

  8. Important: Select only This Organizational-Unit checkbox.

  9. Click OK twice and finish creating the Scheduled Task.

by (3.2k points)
0

Thank you Support2 this worked perfectly.

Related questions

Is it possible to configure a trigger so that it automatically removes an AD user from an AD group, x days after they were added? For instance, if we have a group ... in an attribute, then comparing to that in the removal action? Thanks for any advice!

asked 29 minutes ago by 3Jake (170 points)
0 votes
1 answer

I have found the script to force membership updates for all rule based groups, but is there a script to force update a specific rule based group? I am looking to add a ... I would like to trigger a rule based group that adds members of the manual group. Thanks

asked Jul 9 by msheppard (860 points)
0 votes
1 answer

Hi, I want to add approval for specific groups with temporary membership based on this script: https://www.adaxes.com/script-repository/temporary-group-membrship-s533. ... full script be executed until $Context.SubmitForApproval and then the rest is on hold?

asked Apr 11 by wintec01 (2.3k points)
0 votes
1 answer

I am trying to build a custom command to add a specific user to a rule based group in adaxes and I am curious if it is something we can use the API to complete?

asked Mar 7 by Brian (40 points)
0 votes
1 answer

In Adaxes version 2023.2 is it possible to do any Entra/M365 group membership changes directly from the Helpdesk UI? For example, can I add an on prem user to Entra ... the Helpdesk portal with out the use of a scheduled task, business rule or custom action?

asked Feb 19 by mfisher (150 points)
0 votes
1 answer