Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Dim EmailAddress1, SMTPServer
- Dim resultoutput
- Dim arrExpUsers() : intSize=0 : i=0
- Dim arrExpUsers1() : intSize1=0
- Resultoutput = ""
- '==========================================================================
- 'Here are Your Config Variables
- SMTPServer = "relay.ipacc.com"
- EmailAddress1 = "charles.sims@ipacc.com" & "," & "jack.obitts@ipacc.com" & "," & "scott.page@ipacc.com" & "," & "john.courington@ipacc.com"
- '==========================================================================
- dt = FormatDateTime(Date(),vbshortdate) & " " & Time()
- Const MULTIVALUED = "Variant()"
- Set fs=createobject("Scripting.FileSystemObject")
- diaccdir = "\\bhmfs02a\Groups\IT\Shared\Internal Audit\SOX Requests\Active Directory"
- Set fl = fs.Getfolder(diaccdir)
- for each f in fl.files
- if Right(f.Name,3) = "csv" then
- If IsNull(filedate) Or f.DateCreated > filedate Then
- filename = f.Name
- End If
- End if
- Next
- Set objTextFile = fs.OpenTextFile(diaccdir & "\" & filename)
- do Until objtextfile.atendofstream
- strnextline = objtextfile.readline
- arrExpiredAccount = Split(strnextline,",")
- If (arrExpiredAccount(5) = "No ") OR (arrExpiredAccount(5) = "Never") OR (arrExpiredAccount(3) = "Yes") OR (arrExpiredAccount(5) = "AcctExpiresTime") Then
- ' dont do anything
- Else
- NowDate = arrExpiredAccount(5)
- datearray = split(NowDate,"/")
- wda = left(datearray(2),4) & Right("0" & datearray(0),2) & Right("0" & datearray(1),2) & "000000"
- expDate = GetVBDate(wda)
- if datediff("y",dt,expDate) < 19 AND datediff("y",dt,expDate) > 0 Then
- ReDim Preserve arrExpUsers(intSize)
- arrExpUsers(intSize) = arrExpiredAccount(0)
- intSize = intSize + 1
- ReDim Preserve arrExpUsers(intSize)
- arrExpUsers(intSize) = arrExpiredAccount(1)
- intSize = intSize + 1
- ReDim Preserve arrExpUsers(intSize)
- arrExpUsers(intSize) = arrExpiredAccount(5)
- intSize = intSize + 1
- end if
- end if
- Loop
- If (typename(arrExpUsers) = MULTIVALUED) Then
- For i = 0 to intsize - 1 Step 3
- On Error Resume Next
- Dim oConn: Set oConn = CreateObject("ADODB.Connection")
- oConn.Open "Provider=ADsDSOObject;"
- Set oCommand = CreateObject("ADODB.Command")
- oCommand.ActiveConnection = oConn
- oCommand.CommandText = "<LDAP://dir.ipacc.com:389/ou=People,o=ipacc.com,o=infinity>;(&(objectClass=inetOrgPerson)(uid=" & arrexpusers(i+1) & "));ADsPath;subtree" 'ou=People,o=ipacc.com,o=infinity
- Set objResults = oCommand.Execute
- If not objResults.EOF Then
- objResults.MoveFirst
- Set objUser1 = GetObject(objResults.Fields("AdsPath"))
- ReDim Preserve arrExpUsers1(intSize1)
- arrExpUsers1(intSize1) = objUser1.uid 'first.last
- intSize1 = intSize1 + 1
- ReDim Preserve arrExpUsers1(intSize1)
- arrExpUsers1(intSize1) = arrexpusers(i+2) 'expiration date
- intSize1 = intSize1 + 1
- ReDim Preserve arrExpUsers1(intSize1)
- arrExpUsers1(intSize1) = objuser1.manager & "@ipacc.com" 'objmgr1.mail 'manager email
- intSize1 = intSize1 + 1
- ReDim Preserve arrExpUsers1(intSize1)
- arrExpUsers1(intSize1) = objuser1.mail 'email??
- intSize1 = intSize1 + 1
- End if
- Next
- End if
- set i=0
- wscript.echo(intsize1)
- If (typename(arrExpUsers1) = MULTIVALUED) Then
- For i = 0 to intsize1 - 1 Step 4
- Resultoutput = resultoutput & arrExpUsers1(i) & " EMail: " & arrExpUsers1(i+3) & " Expires on " & arrExpUsers1(i+1) & " Manager: " & arrexpusers1(i+2) & vbnewline
- EmailAddress1=EmailAddress1 & "," & arrexpusers1(i+2)
- subjto = arrexpusers1(i+5) & "@ipacc.com"
- msgmessage = arrExpUsers1(i) & " Expires on " & arrExpUsers1(i+1)
- 'send_MGR_email
- Next
- end if
- wscript.echo(resultoutput)
- Call Send_Email
- Public Sub Send_Email
- Set objMessage = CreateObject("CDO.Message")
- objMessage.Subject = "Account Expiry Report for " & dt
- objMessage.From = "AccountExpiryReport@ipacc.com"
- objMessage.To = EmailAddress1
- objMessage.TextBody = _
- "!! Please read carefully !!" & vbnewline & _
- "This report runs automatically every 2 weeks to alert the managers (as reported by HR)" & vbnewline & _
- "of contractors/vendors whose VPN accounts (remote access) are getting close to expiring. An expired account" & vbnewline & _
- "will no longer have access to our systems and could be disruptive to completing projects for which they were contracted." & vbnewline & _
- "This is informing you that a user that may report to you has an account expiring in the next 19 days." & vbnewline & _
- "If you need to extend the account please submit a help desk ticket or if the account needs to be deleted" & vbnewline & _
- "please submit a ticket asking that the account be removed." & vbnewline & _
- vbnewline & _
- "Please contact the Corporate Help Desk if you have any questions." & vbnewline & _
- vbnewline & _
- "Thank you." & vbnewline & _
- vbnewline & _
- "*** This is automatically generated email � please do not reply ***" & vbnewline & _
- vbnewline & _
- resultoutput
- '==This section provides the configuration information for the remote SMTP server.
- '==Normally you will only change the server name or IP.
- objMessage.Configuration.Fields.Item _
- ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
- 'Name or IP of Remote SMTP Server
- objMessage.Configuration.Fields.Item _
- ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = SMTPServer
- 'Server port (typically 25)
- objMessage.Configuration.Fields.Item _
- ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
- objMessage.Configuration.Fields.Update
- '==End remote SMTP server configuration section==
- objMessage.Send
- End Sub
- Function GetVBDate(wd)
- GetVBDate = DateSerial(left(wd,4),mid(wd,5,2),mid(wd,7,2)) + TimeSerial(mid(wd,9,2),mid(wd,11,2),mid(wd,13,2))
- End Function
- sub Send_MGR_Email
- Set objMessage = CreateObject("CDO.Message")
- objMessage.Subject = "Account Expiry Report for " & dt
- objMessage.From = "AccountExpiryReport@ipacc.com"
- objMessage.To = subjto
- objMessage.TextBody = _
- "!! Please read carefully !!" & vbnewline & _
- "This report runs automatically every 2 weeks to alert the managers (as reported by HR)" & vbnewline & _
- "of contractors/vendors whose VPN accounts (remote access) are getting close to expiring. An expired account" & vbnewline & _
- "will no longer have access to our systems and could be disruptive to completing projects for which they were contracted." & vbnewline & _
- "This is informing you that a user that may report to you has an account expiring in the next 19 days." & vbnewline & _
- "If you need to extend the account please submit a help desk ticket or if the account needs to be deleted" & vbnewline & _
- "please submit a ticket asking that the account be removed." & vbnewline & _
- vbnewline & _
- "Please contact the Corporate Help Desk if you have any questions." & vbnewline & _
- vbnewline & _
- "Thank you." & vbnewline & _
- vbnewline & _
- "*** This is automatically generated email � please do not reply ***" & vbnewline & _
- vbnewline & _
- msgmessage
- '==This section provides the configuration information for the remote SMTP server.
- '==Normally you will only change the server name or IP.
- objMessage.Configuration.Fields.Item _
- ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
- 'Name or IP of Remote SMTP Server
- objMessage.Configuration.Fields.Item _
- ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = SMTPServer
- 'Server port (typically 25)
- objMessage.Configuration.Fields.Item _
- ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
- objMessage.Configuration.Fields.Update
- '==End remote SMTP server configuration section==
- objMessage.Send
- End sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement