Script repository

Scheduled tasks executed on a specific service

Updated on: Jan 18, 2026, Views: 2749

Export data

The script emails the list of scheduled tasks that are configured to run on a specific instance of Adaxes service. To execute the script, create a scheduled task configured for the Domain object type and add a managed domain to the Activity Scope of the task. The domain will only be used to trigger execution of the scheduled task.

Parameters

  • $ownerServiceDnsHostName - the fully-qualified domain name (FQDN) of the Adaxes service where a scheduled task should be configured to run to be included into the email notification.
  • $to - the address of the email notification recipient.
  • $subject - the email notification subject.
  • $reportHeader - the report header.
  • $reportFooter - the report footer.
$ownerServiceDnsHostName = "Server.domain.com" # TODO: modify me

# Email settings
$to = "recipient@domain.com" # TODO: modify me
$subject = "Scheduled Task report" # TODO: modify me
$reportHeader = "<h2>Scheduled Task report</h2>"
$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

# Build criteria
$criteria = New-AdmCriteria "adm-ScheduledTask" -Expression {adm-SyncRootOwnerDnsHostName -eq $ownerServiceDnsHostName}

# Search parameters
$scheduledTasksContainerPath = $Context.GetWellKnownContainerPath("ScheduledTasks")
$searcher = $Context.BindToObject($scheduledTasksContainerPath)
$searcher.Criteria = $criteria
$searcher.SearchScope = "ADS_SCOPE_SUBTREE"
$searcher.ReferralChasing = "ADS_CHASE_REFERRALS_NEVER"
$searcher.PageSize = 500

try
{
    # Execute search
    $searchResultIterator = $searcher.ExecuteSearch()
    $searchResults = $searchResultIterator.FetchAll()
    
    $htmlList = New-Object "System.Text.StringBuilder"
    [void]$htmlList.Append("<ol>")
    $scheduledTasksContainerPathObj = New-Object Softerra.Adaxes.Adsi.AdsPath $scheduledTasksContainerPath
    foreach ($searchResult in $searchResults)
    {
        $taskPath = $searchResult.AdsPath.ToString()
        $taskPath = $taskPath.Replace($scheduledTasksContainerPathObj.DN, "")
        $taskName = $Context.GetDisplayNameFromAdsPath($taskPath.Trim(","))
        [void]$htmlList.Append("<li>$taskName</li>")
    }
    [void]$htmlList.Append("</ol>")
}
finally
{
    # Release resources
    if ($searchResultIterator) { $searchResultIterator.Dispose() }
}

# Build html
$html = New-Object "System.Text.StringBuilder"
$html.Append($reportHeader)
$html.Append($htmlList.ToString())
$html.Append($reportFooter)

# Send mail
$Context.SendMail($to, $subject, $NULL, $html.ToString())

Comments 0

You must be signed in to comment.

    Got questions?

    Support Questions & Answers

    We use cookies to improve your experience.
    By your continued use of this site you accept such use.
    For more details please see our privacy policy and cookies policy.