Script Repository

Recently modified groups

January 11, 2017

The script generates and emails an HTML-formatted report containing recently modified groups.

To generate the reports upon request, you can create a Custom Command that runs the script. To schedule the reports, you need to create a Scheduled Task configured for the Domain-DNS object type and run it against any of your AD domains.

To add the script to a Custom Command or Scheduled Task, use the Run a program or PowerShell script action.


  • $numDays - specifies the number of days during which a group needs to be modified to be included in the report.
  • $to - specifies email addresses of the recipient(s) of the report;
  • $subject - specifies the email message subject;
  • $reportHeader - specifies the email message header;
  • $reportFooter - specifies the email message footer.
Edit Remove
$numDays = 30 # TODO: modify me

# Email message settings
$to = "" # TODO: modify me. Insert %adm-InitiatorEmail% if you want to send the report to the operation initiator.
$subject = "My Subject" # TODO: modify me
$reportHeader = @"
<h1><b>Recently Modified Groups</b></h1><br/>
<table border="1">
        <th>When Changed</th>
"@ # TODO: modify me

$reportFooter = @"

<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 BuildHtmlReport($numDays, $reportHeader, $reportFooter)
    # Search groups
    $startDate = "{0:yyyyMMddHHmmss}.0Z" -f (Get-Date).AddDays(-$numDays)

    $searcher = New-Object "Softerra.Adaxes.Adsi.Search.DirectorySearcher" $NULL, $False
    $searcher.SearchParameters.PageSize = 500
    $searcher.SearchParameters.SearchScope = "ADS_SCOPE_SUBTREE"
    $searcher.SearchParameters.Filter = "(&(objectCategory=group)(whenChanged>=$startDate))"
    $searcher.SearchParameters.ReferralChasing = "ADS_CHASE_REFERRALS_NEVER"
    $searcher.SearchParameters.VirtualRoot = $True
        # Build HTML report
        $searchResult = $searcher.ExecuteSearch()
        foreach ($groupID in $searchResult.FetchAll())
            $name = $groupID.Properties["name"].Value
            $description = $groupID.Properties["description"].Value
            $dn = $groupID.Properties["distinguishedName"].Value
            $dateChanged = ($groupID.Properties["whenChanged"].Value).ToString()
            $domain = $Context.GetObjectDomain($dn)
            # Add to report
            $reportHeader += "<tr><td>$name</td><td>$description</td><td>$domain</td><td>$dateChanged</td></tr>" 
        $reportHeader += "</table>"
        $htmlReport = $reportHeader + $reportFooter
    return $htmlReport

$htmlReport = BuildHtmlReport $numDays $reportHeader $reportFooter
$Context.SendMail($to, $subject, $NULL, $htmlReport)

Comments ( 0 )
No results found.
Leave a comment