Quantcast
Channel: TechCenter
Viewing all articles
Browse latest Browse all 2350

Alert on pending approval request expiration

$
0
0
Revision 1 posted to Active Roles Script Center by DELL-Tatiana G on 2/24/2014 4:03:00 AM

Back to PowerShell samples

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@example.com>, "User2" <User2@example.com>, "User3" <User3@example.com>) ,
  • MailFrom - The e-mail addresses of the principal author or authors of this message,
  • ArsUrl - the URL of ARS Self service site


Screenshort of notification email

Pending_approval_request_expiration_mail.jpg

SCRIPT

 

# 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.com"

# Set the email subject

$Subject = "Pending approval request expiration"

# Set recipients of alert

$MailTo = "example1@example.com"

# 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()

}

Back to PowerShell samples


Viewing all articles
Browse latest Browse all 2350

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>