Hello,
Thank you for the confirmation. To create the Scheduled Task:
- Launch Adaxes Administration Console.
- In the Console Tree, right-click your service node.
- In the context menu, navigate to New and click Scheduled Task.
- On step 3 of the Create Scheduled Task wizard, select the User object type and click Next.
- Click Add an action.
- Select Run a program or PowerShell script.
- Paste the below script into the script field. In the script:
- $filePath - Specifies the path to the text file that will be created.
- $removeFile - Specifies whether the text file should be removed after being emailed.
- $to - Specifies the email address of the notification recipient.
- $subject - Specifies the email notification subject.
- $defaultMessage - Specifies the text of the email notification that will be sent when a log record for disabling the user with a non-empty execution log is found.
- $messageNoLogFound - Specifies the text of the email notification that will be sent when no log records are found for disabling a user.
- $messageNoExecutionLog - Specifies the text of the email notification that will be sent when the log record for disabling a user has an empty execution log. In the text\, the {0} placeholder will be replaced with the date when the user was disabled.
- $from - Specifies the email address from which notifications will be sent.
- $smtpServer -Specifies the SMTP server that will be used to send email notifications.
# File settings
$filePath = "C:\Scripts\MyFile.txt" # TODO: modify me
$removeFile = $True # TODO: modify me
# E-mail settings
$to = "recipient@domain.com" # TODO: modify me
$subject = "Disabled user %fullname%" # TODO: modify me
$defaultMessage = "Disabled user %fullname%" # TODO: modify me
$messageNoLogFound = "User %fullname% was disabled but no log was found." # TODO: modify me
$messageNoExecutionLog = "User %fullname% was disabled by Adaxes at {0}" # TODO: modify me
$from = "noreply@domain.com" # TODO: modify me
$smtpServer = "mail.domain.com" # TODO: modify me
function GetExecutionLog ($logEntryCollection, $executionLog, $tabbing)
{
$tabbing++
foreach ($logEntry in $logEntryCollection)
{
# Get operation info
$type = $logEntry.Type
$message = $logEntry.Message
$source = $logEntry.Source
# Build report record
$messageBuilder = "".PadLeft(4 * ($tabbing - 1))
if (-not([System.String]::IsNullOrEmpty($source)))
{
# Add source to the message
$messageBuilder += "$source`: "
}
$messageBuilder += "$type - $message"
$messageBuilder = $messageBuilder -replace "`t|`n|`r",""
# Add message to report
[void]$executionLog.AppendLine($messageBuilder)
# Add subentries, if any
$subEntries = $logEntry.SubEntries
if ($subEntries.Count -ne 0)
{
GetExecutionLog $subEntries $executionLog $tabbing
}
}
}
# Get modification log records
$modificationLog = $Context.TargetObject.GetModificationLog()
$log = $modificationLog.Log
# Get the current page of log records
$logRecords = $log.GetPage(0)
# Get information contained in each record
$executionLog = New-Object System.Text.StringBuilder
foreach ($record in $logRecords)
{
$operationTypes = $record.GetOperationTypes()
if ($operationTypes -notcontains "disable account")
{
continue
}
# Get execution log
GetExecutionLog $record.GetExecutionLog() $executionLog 0
$completionTime = $record.CompletionTime
break
}
$parameters = @{
"To" = $to
"From" = $from
"SmtpServer" = $smtpServer
"Subject" = $subject
}
if ($NULL -eq $completionTime)
{
$parameters.Add("Body", $messageNoLogFound)
}
elseif ($executionLog.Length -eq 0)
{
$parameters.Add("Body", [System.String]::Format($messageNoExecutionLog, @($completionTime)))
}
else
{
$executionLog.ToString() | Out-File $filePath
$parameters.Add("Body", $defaultMessage)
$parameters.Add("Attachments", $filePath)
}
# Send report
Send-MailMessage @parameters
if ($removeFile)
{
# Remove temporary file
Remove-Item $filePath -Force -ErrorAction SilentlyContinue
}
- Enter a short description and click OK.
- Right-click the action you created and click Add New Action.
- Select Update the user and click Add.
- In the Property to modify drop-down, select CustomAttributeBoolean1.
- In the New value drop-down, select True.
- Click OK twice.
- Right-click the action you created and click Add Condition.
- Select If If <property> <relation> <value>.
- Select If CustomAttributeBoolean1 does not equal True and click OK.
- Right-click the action you created and click Add Condition again.
- Select If account is enabled / disabled / locked.
- Select disabled and click OK.
- Click Next and finish creating the Scheduled Task. The task should look like the following: