DESCRIPTION
When deprovision users, this script read all parameters from the Deprovision Policy and based on VA we send emails notifications to application's managers.
SCRIPT
Sub onDeprovision(ByVal Request)
' ********************************************************
' Set SMTP constants (Provided by Steven Schullo)
strCmdMailCC = ""
strCmdMailFrom = "ActiveRolesServer@dom.es"
constSmtpPort = 25
constSmtpServer = "email.dom.local"
strCmdSubject = "User Deprovisioning"
' Open error file for tracking.
errores = "E:\Quest Software\Scripts\traza.txt"
objErrorFile = CreateObject("Scripting.FileSystemObject")
ErrorFile = objErrorFile.OpenTextFile(errores, 8, True)
' Get Time and Data for Error file
On Error Resume Next
LineaTiempo = Date
LineaTime = Time
Dim MyVar
If (LCase(Request.Class) <> "user") Then Exit Sub
' Obtain user data
Dim objUser
objUser = GetObject("EDMS://" & request.name)
objuser.getinfo
ErrorFile.WriteLine("*******************************************")
ErrorFile.WriteLine(LineaTiempo & "-" & LineaTime & ": Inicio Deprovision")
' Bind to deprovisioning policy
objPO = GetObject("EDMS://CN=Depro-Prueba,CN=TELE5,CN=Policy Objects,CN=Configuration")
' We obtain all policies for deprovisioning policy
For Each APE In objPO
' Now we read all script parameters of the script policy.
For Each Param In APE
VaValue = CStr(Param.Value)
App = CStr(Param.Name)
' We compare if the parameter is a VA.
If Left(VaValue, 5) = "edsva" Then
ErrorFile.WriteLine(LineaTiempo & "-" & LineaTime & ": Encontrado VA a tratar " & VaValue)
' If the parameter is VA now we select the manager (Other Parameter)
For Each Param2 In APE
Val2 = Param2.Name
Manager = Param2.Value
If VaValue = Val2 Then
ErrorFile.WriteLine(LineaTiempo & "-" & LineaTime & ": Obtenemos datos del Usuario: " & objUser.Get("name"))
objUser.GetInfoEx Array(VaValue), 0
MyVar = CStr(objUser.Get(VaValue))
If MyVar = "True" Then
strCmdMsgText = "El usuario " & objUser.Get("name") & " Ha sido dado de baja. Por favor proceda" & vbCRLF
strCmdMsgText = strCmdMsgText & "a darlo de baja de " & App
ErrorFile.WriteLine(LineaTiempo & "-" & LineaTime & ": Envio Correo para " & App)
' After setting the message text, we call Email sub for sending the message
Email(strCmdMailFrom, Manager, strCmdSubject, strCmdMsgText, constSmtpServer)
Else
strCmdMsgText = "El usuario " & objUser.Get("name") & " No estaba dado de alta en " & App
ErrorFile.WriteLine(LineaTiempo & "-" & LineaTime & ": " & strCmdMsgText)
End If
End If
Next
End If
Next
Next
ErrorFile.close()
End Sub
' ********************************************************
' Email sent using CDO (Provided by Steven Schullo)
Sub Email(ByVal strCmdMailFrom, ByVal strCmdMailTo, ByVal strCmdSubject, ByVal strCmdMsgText, ByVal constSmtpServer)
objEmail = CreateObject("CDO.Message")
objEmail.From = strCmdMailFrom
objEmail.To = strCmdMailTo
objEmail.Subject = strCmdSubject
objEmail.Textbody = strCmdMsgText
objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = constSmtpServer
objEmail.Configuration.Fields.Update()
objEmail.Send()
End Sub