0 votes

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

0 votes
by (272k points)
selected by
Best answer

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.

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())
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.

0

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

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.

0

Thank you Support2 this worked perfectly.

Related questions

0 votes
1 answer

We are looking for a way to allow AD users to manage group memberships of groups they have been set as Manager for - and would like to know if we can achieve this with Adaxes? We are thinking a easy to use web portal.

asked Apr 17 by Nicolaj Rasmussen (20 points)
0 votes
1 answer

I'm trying to implement the script on https://www.adaxes.com/script-repository/changes-in-group-membership-including-changes-made-by-3rd-party-tools-s289.htm. I added my ... is set to run hourly on Domain Admins, and Exchange Admin "group" objects. Thanks

asked Feb 26 by stevehalvorson (110 points)
0 votes
1 answer

We have several Office 365 groups where the someone is an Owner but not a Member, and we'd like to give them the ability through the web interface to give them the ability ... option in the web interface to allow them to add or remove users via a custom task?

asked Nov 1, 2023 by PaulO (20 points)
0 votes
1 answer

Is it possible using PowerShell to copy group memberships from an already existing user without copying 2 specific groups named for example test and test 1 ? We are currently ... groups are not included. I can share the PowerShell script if needed. KR, Cas

asked Oct 30, 2023 by Cas (150 points)
0 votes
0 answers

Good Morning, Interesting issue, newly created users created in Adaxes don't show AD group membership when viewing in Adaxes but the groups show normally in AD. Users ... idea why users crearted in Adaxes cannot see the groups while other users appear fine?

asked Aug 2, 2023 by curtisa (210 points)
3,355 questions
3,054 answers
7,799 comments
545,152 users