0 votes

We are looking for a report to email our alerts email address after each scheduled tasks runs. It should report the successful and non successful operations alike. We are wanting to double check our scripts and pulling the log files is only available from the server itself.

Thanks in advance.

by (3.2k points)

1 Answer

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

Hello,

There is no possibility to send an email once a Scheduled Task is run. It is only possible to email alerts of all operations initiated by Scheduled Tasks for a certain period of time. If such a solution meets your requirements, we will provide you with detailed instructions.

0

can we set that scheduled time time for the last 24 hours? If so we would like to have that script created please.

0

I think that may fit the need of what we want to see. Please provide the instructions.

0

Hello,

Yes, sure. For this purpose, you need to create a Scheduled Task that runs the following script from our Script Repository: http://www.adaxes.com/script-repository ... y-s223.htm.

To create it:

  1. Create a new Scheduled Task.
  2. On step 3 of the Create Scheduled Task wizard, select Show all object types, then select Domain-DNS.
  3. Add the Run a program or PowerShell script action and paste the script from the repository.
  4. Modify script parameters, add a short description and click OK.
  5. Click Next. On this step, click Add and select any AD domain. The selected domain will be used only to trigger execution of the PowerShell script and will not affect the scope of log reports included in the report.
  6. Click OK two times, and then click Finish.
0

This is only returning when the scheduled task was run, we are wanting the contents of what happened when the script ran.

0

Hello,

Do we understand correctly, that you need a report that will email alerts only for PowerShell scripts executed by a Scheduled Task? If you do, find the updated script below:

$taskName = "Inactive User Deleter" # TODO: modify me
$numDays = 1 # set to 0 to output all log records
$operationTypes = @("run script") # TODO: modify me. Values: $NULL or Operation types array 
$to = "recipient@domain.com" # TODO: modify me
$subject = "Actions performed by $taskName" # TODO: modify me
$reportHeader = @"
<b>Actions performed by $taskName during the last $numDays days</b><br/><br/>
<table border="1">
    <tr>
        <th>Start Time</th>
        <th>Completion Time</th>
        <th>Target Object</th>
        <th>Target Object Type</th>
        <th>Operation</th>
        <th>Execution Log</th>
    </tr>
"@ # 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 GetExecutionLog ($logEntryCollection, $executionLog)
{
    $executionLog += "<ul>"
    foreach ($logEntry in $logEntryCollection)
    {
        # Get the operation info
        $type = $logEntry.Type
        $message = $logEntry.Message
        $source = $logEntry.Source

        # Build report entry
        $messageBuilder = ""
        if (-not([System.String]::IsNullOrEmpty($source)))
        {
            # Add source to the message
            $messageBuilder += "$source`: "
        }
        $messageBuilder += "$type - $message"

        # Encode HTML tags
        $messageBuilder = [System.Web.HttpUtility]::HtmlEncode($messageBuilder)

        # Add entry to the report
        $executionLog += "<li>$messageBuilder"

        # Add Execution Log, if any
        $subEntries = $logEntry.SubEntries
        if ($subEntries.Count -ne 0)
        {
            $executionLog = GetExecutionLog $subEntries $executionLog
        }
        $executionLog += "</li>"
    }
    $executionLog += "</ul>"
    return $executionLog
}

# Bind to the directory object representing the General Log
$path = $Context.GetWellKnownContainerPath("ServiceLog")
$serviceLog = $Context.BindToObject($path)

$generalLog = $serviceLog.GeneralLog

# Set start and end dates
if ($numDays -ne 0)
{
   $generalLog.StartDateTime = (Get-Date).AddDays(-$numDays)
   $generalLog.EndDateTime = Get-Date
}

# Get the log records
$log = $generalLog.Log
$records = $log.GetPage(0)

# Add log records to the report
foreach ($record in $records)
{
    if ($record.Initiator.Name -ine $taskName)
    {
        continue
    }

    # Check operation
    if ($operationTypes -ne $NULL)
    {
        $recordOperationTypes = $record.GetOperationTypes()
        $result = Compare-Object -ReferenceObject $recordOperationTypes -DifferenceObject $operationTypes -IncludeEqual -ExcludeDifferent
        if ($result -eq $NULL)
        {
            continue
        }
    }

    if ($record.State -eq "OPERATION_STATE_FAILED_NO_CONTINUE")
    {
        $reportRecord = "<tr bgcolor='red' valign='top'>"
    }
    elseif ($record.State -eq "OPERATION_STATE_FAILED_CAN_CONTINUE")
    {
        $reportRecord = "<tr bgcolor='yellow' valign='top'>"
    }
    else
    {
        $reportRecord = "<tr valign='top'>"
    }

    # Get log record properties
    $recordStartTime = $record.StartTime 
    $recordCompletionTime = $record.CompletionTime
    $recordTargetObjectName = $record.TargetObjectName
    $recordTargetObjectType = $record.TargetObjectType
    $recordDescription = $record.Description

    # Add the Execution Log
    $executionLogEntries = $record.GetExecutionLog()

    if ($executionLogEntries.Count -eq 0)
    {
        $executionLog = "Execution Log is empty"
    }
    else
    {
        # Add execution log to the report
        $executionLog = GetExecutionLog $executionLogEntries ""
    }

    $reportRecord += "<td>$recordStartTime</td><td>$recordCompletionTime</td><td>$recordTargetObjectName</td><td>$recordTargetObjectType</td><td>$recordDescription</td><td>$executionLog</td>"
    $reportRecord += "</tr>"

    # Add record to the report
    $reportHeader += $reportRecord
}
$reportHeader += "</table>"
$messageBody = $reportHeader + $reportFooter

# Send report
$Context.SendMail($to, $subject, $NULL, $messageBody)

If you need a report to email other information, please provide us with as much details per your request as you can.

0

We have several scheduled tasks that run all hours of the night. We would like a detailed summary of what happened during that specific task, successes or failures. One task is to update the end users department (which in return updates city, state and department attributes as well). We would like this report to email what happened during the time this task ran. Details are in the log but not everyone has access to the server where the console is.

0

Hello,

We have provided you with a script that emails an HTML report on the activity of a certain Scheduled Task and another one that emails alerts only for PowerShell scripts executed by a certain Scheduled Task. Do these scripts not meet your needs? If that is so, could you provide us with all the possible details regarding the report that you need?

Related questions

0 votes
1 answer

Hi, I copied report "recently created users" and added a parameter to check for specific value in extensionAttribute3. If this attributes starts with e.g. value "startdate" , only those users ... $null, * , %%, ? , ...) Any idea how to build the report?

asked Jul 7, 2023 by wintec01 (1.1k points)
0 votes
1 answer

We use TOPdesk as our ITSM solution. Several departments are able to create new users. When a create user task fails we would like to receive the alert as the Adaxes ... Adaxes to sent out the incident to our TOPdesk. Is there a solution for this?

asked Oct 5, 2023 by mrkvd16 (20 points)
0 votes
1 answer

Is it possible to grant selected user option to add custom license plan (or just subset of its licenses) to given user(s) using web interface?

asked Feb 28, 2023 by KIT (910 points)
0 votes
1 answer

I came across Adaxes, and thought it looked interesting, but as an IT provider, providing system administration for multiple small companies, the pricing would never be ... some administrative accounts/helpdesk access to only a selection of the companies, etc?

asked Feb 3, 2023 by he (20 points)
0 votes
1 answer

We need your help, as we are trying to activate the license but we are not able to see that option. Please find the below screenshot for your reference.

asked Aug 24, 2022 by msharma2 (20 points)
3,346 questions
3,047 answers
7,782 comments
544,989 users