DESCRIPTION
This is a sample that sends email with list of pending approval for which there is no decision more than a few days.
How to use
To use this script, import this script as a new powershell scheduled task script module and create a new scheduled task in ARS, referencing new script module.
The parameters that need to change:
- SmtpServer - the DNS or NetBIOS name of the host to which to post the message using the SMTP protocol,
- MailTo - commas separate multiple recipients in the list: ("User1" <User1@e[[ars-script-wiki&mce_rdomain=dell.com:mailto:User1@example.com|]]xample.com>, "User2" <User2@exam[[ars-script-wiki&mce_rdomain=dell.com:mailto:User2@example.com|]]ple.com>, "User3" <User3@exa[[ars-script-wiki&mce_rdomain=dell.com:mailto:User3@example.com|]]mple.com>) ,
- MailFrom - The e-mail addresses of the principal author or authors of this message,
- ArsUrl - the URL of ARS Self service site
SCRIPT
#*********************************************************************************
# THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
# EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
#
# IF YOU WANT THIS FUNCTIONALITY TO BE CONDITIONALLY SUPPORTED,
# PLEASE CONTACT ONE IDENTITY PROFESSIONAL SERVICES.
#*********************************************************************************
# number of days before sending alerts
$days = 10
# Set the DNS or NetBIOS name of the host to which to post the message
# using the SMTP protocol.
$SmtpServer = "smtp.mycompany.com"
# Set the port on which the SMTP service is listening
$SmtpPort = 25
# Set the From of email
$MailFrom = "Administrator@mycompany[[ars-script-wiki&mce_rdomain=dell.com:mailto:Administrator@mycompany.com|]].com"
# Set the email subject
$Subject = "Pending approval request expiration"
# Set recipients of alert
$MailTo = "example1@example.co[[ars-script-wiki&mce_rdomain=dell.com:mailto:example1@example.com|]]m"
# Set the URL of ARS Self service site
$ARSurl = "http://ars.mycompany.com/ARServerSelfService"
$MsgText = "The following Active Directory operations are pending approval for more than $days days:"
$needToSend = $false
$now = [DateTime]::Now
$datebefore = $now.AddDays(-$days)
Get-QARSApprovalTask -TaskStatus "Pending" -CreatedBefore $datebefore |
%{
$elapsed = $now - $_.Created
$needToSend = $true
$id = $_.ID
# Link to Approval task
$MsgText += "<p><a href=""$ARSurl/Approval/SearchResult.aspx?TaskID=TASK_BY_ID&itemID=$id"">$id</a>"
$MsgText += " created " + $elapsed.Days + " days ago, pending approval of "
# list of approvers
$first = $true
$_.Approvers |
%{
if ($first -ne $true) {$MsgText += ", "}
$first = $false
$MsgText += $_.NTAccountName
}
$MsgText += "</p>"
}
if ($needToSend)
{
# Specify that the message will be sent using the network
# (SMTP over the network).
$CdoSendUsingPort = 2
$Msg = New-Object -ComObject "CDO.Message"
$Msg.From = $MailFrom
$Msg.To = $MailTo
$Msg.Subject = $Subject
$Msg.HTMLBody = $MsgText
# Configure message
$Msg.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = $CdoSendUsingPort
$Msg.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = $SmtpServer
$Msg.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = $SmtpPort
$Msg.Configuration.Fields.Update()
# Send message
$Msg.Send()
}