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.

Script Repository

Scheduled tasks executed on a specific service

February 25, 2021 Views: 791

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-DNS object type and add a managed domain to the Activity Scope of the task.


  • $ownerServiceDnsHostName - Specifies 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 - Specifies the email notification recipient.
  • $subject - Specifies the email notification subject.
  • $reportHeader - Specifies the report header.
  • $reportFooter - Specifies the report footer.
Edit Remove
$ownerServiceDnsHostName = "Server.domain.com" # TODO: modify me

# E-mail 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

# Search configuration objects
$scheduledTasksContainerPath = $Context.GetWellKnownContainerPath("ScheduledTasks")
$searcher = $Context.BindToObject($scheduledTasksContainerPath)
$searcher.SearchFilter = "(&(objectCategory=adm-ScheduledTask)(adm-SyncRootOwnerDnsHostName=$ownerServiceDnsHostName))"
$searcher.SearchScope = "ADS_SCOPE_SUBTREE"
$searcher.PageSize = 500

    $searchResultIterator = $searcher.ExecuteSearch()
    $searchResults = $searchResultIterator.FetchAll()
    $htmlList = New-Object "System.Text.StringBuilder"
    $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(","))
    # Release resources
    if ($searchResultIterator) { $searchResultIterator.Dispose() }

# Build html
$html = New-Object "System.Text.StringBuilder"

# Send mail
$Context.SendMail($to, $subject, $NULL, $html.ToString())
Comments 0
Leave a comment

Got questions?

Support Questions & Answers