Advertisement
Guest User

What's wrong...

a guest
Dec 24th, 2015
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. Dim EmailAddress1, SMTPServer
  3. Dim resultoutput
  4. Dim arrExpUsers() : intSize=0 : i=0
  5. Dim arrExpUsers1() : intSize1=0
  6. Resultoutput = ""
  7.  
  8. '==========================================================================
  9. 'Here are Your Config Variables
  10. SMTPServer = "relay.ipacc.com"
  11. EmailAddress1 = "charles.sims@ipacc.com" & "," & "jack.obitts@ipacc.com" & "," & "scott.page@ipacc.com" & "," & "john.courington@ipacc.com"
  12. '==========================================================================
  13. dt = FormatDateTime(Date(),vbshortdate) & " " & Time()
  14. Const MULTIVALUED       = "Variant()"
  15.  
  16. Set fs=createobject("Scripting.FileSystemObject")
  17. diaccdir = "\\bhmfs02a\Groups\IT\Shared\Internal Audit\SOX Requests\Active Directory"
  18. Set fl = fs.Getfolder(diaccdir)
  19.  
  20. for each f in fl.files
  21.     if Right(f.Name,3) = "csv" then
  22.         If IsNull(filedate) Or f.DateCreated > filedate Then
  23.             filename = f.Name  
  24.         End If
  25.     End if
  26. Next
  27.  
  28.  Set objTextFile = fs.OpenTextFile(diaccdir & "\" & filename)
  29.  
  30.  do Until objtextfile.atendofstream
  31.     strnextline = objtextfile.readline
  32.     arrExpiredAccount = Split(strnextline,",")
  33.     If (arrExpiredAccount(5) = "No ") OR (arrExpiredAccount(5) = "Never") OR (arrExpiredAccount(3) = "Yes") OR (arrExpiredAccount(5) = "AcctExpiresTime") Then
  34.      ' dont do anything
  35.     Else
  36.     NowDate = arrExpiredAccount(5)
  37.     datearray = split(NowDate,"/")
  38.     wda = left(datearray(2),4) & Right("0" & datearray(0),2) & Right("0" & datearray(1),2) & "000000"
  39.     expDate = GetVBDate(wda)
  40.     if datediff("y",dt,expDate) < 19 AND datediff("y",dt,expDate) > 0 Then
  41.         ReDim Preserve arrExpUsers(intSize)
  42.             arrExpUsers(intSize) = arrExpiredAccount(0)
  43.             intSize = intSize + 1
  44.         ReDim Preserve arrExpUsers(intSize)
  45.             arrExpUsers(intSize) = arrExpiredAccount(1)
  46.             intSize = intSize + 1
  47.         ReDim Preserve arrExpUsers(intSize)
  48.             arrExpUsers(intSize) = arrExpiredAccount(5)
  49.             intSize = intSize + 1
  50.     end if
  51. end if
  52. Loop
  53.  
  54. If (typename(arrExpUsers) = MULTIVALUED) Then
  55.     For i = 0 to intsize - 1 Step 3
  56.     On Error Resume Next
  57.         Dim oConn: Set oConn = CreateObject("ADODB.Connection")
  58.         oConn.Open "Provider=ADsDSOObject;"
  59.         Set oCommand = CreateObject("ADODB.Command")
  60.         oCommand.ActiveConnection = oConn
  61.         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
  62.         Set objResults = oCommand.Execute
  63.         If not objResults.EOF Then
  64.             objResults.MoveFirst
  65.                 Set objUser1 = GetObject(objResults.Fields("AdsPath"))
  66.                 ReDim Preserve arrExpUsers1(intSize1)
  67.                     arrExpUsers1(intSize1) = objUser1.uid 'first.last
  68.                     intSize1 = intSize1 + 1
  69.                 ReDim Preserve arrExpUsers1(intSize1)
  70.                     arrExpUsers1(intSize1) = arrexpusers(i+2) 'expiration date
  71.                     intSize1 = intSize1 + 1
  72.                 ReDim Preserve arrExpUsers1(intSize1)
  73.                     arrExpUsers1(intSize1) = objuser1.manager & "@ipacc.com" 'objmgr1.mail 'manager email
  74.                     intSize1 = intSize1 + 1
  75.                 ReDim Preserve arrExpUsers1(intSize1)
  76.                     arrExpUsers1(intSize1) = objuser1.mail 'email??
  77.                     intSize1 = intSize1 + 1
  78.         End if
  79.     Next
  80. End if
  81.  
  82. set i=0
  83. wscript.echo(intsize1)
  84. If (typename(arrExpUsers1) = MULTIVALUED) Then
  85.     For i = 0 to intsize1 - 1 Step 4
  86.      Resultoutput = resultoutput & arrExpUsers1(i) & " EMail: " & arrExpUsers1(i+3) & " Expires on " & arrExpUsers1(i+1) & " Manager: " & arrexpusers1(i+2) & vbnewline
  87.      EmailAddress1=EmailAddress1 & "," & arrexpusers1(i+2)
  88.      subjto = arrexpusers1(i+5) & "@ipacc.com"
  89.      msgmessage = arrExpUsers1(i) & " Expires on " & arrExpUsers1(i+1)
  90.      'send_MGR_email
  91.    Next
  92. end if
  93.    
  94.     wscript.echo(resultoutput)
  95.  
  96. Call Send_Email
  97.  
  98. Public Sub Send_Email
  99. Set objMessage = CreateObject("CDO.Message")
  100. objMessage.Subject = "Account Expiry Report for " & dt
  101. objMessage.From = "AccountExpiryReport@ipacc.com"
  102. objMessage.To = EmailAddress1
  103. objMessage.TextBody = _
  104.  "!! Please read carefully !!" & vbnewline & _
  105.  "This report runs automatically every 2 weeks to alert the managers (as reported by HR)" & vbnewline & _
  106. "of contractors/vendors whose VPN accounts (remote access) are getting close to expiring.  An expired account" & vbnewline & _
  107. "will no longer have access to our systems and could be disruptive to completing projects for which they were contracted." & vbnewline & _
  108. "This is informing you that a user that may report to you has an account expiring in the next 19 days." & vbnewline & _
  109. "If you need to extend the account please submit a help desk ticket or if the account needs to be deleted" & vbnewline & _
  110. "please submit a ticket asking that the account be removed." & vbnewline & _
  111.  vbnewline & _
  112. "Please contact the Corporate Help Desk if you have any questions." & vbnewline & _
  113.  vbnewline & _
  114. "Thank you." & vbnewline & _
  115.  vbnewline & _
  116. "*** This is automatically generated email � please do not reply ***" & vbnewline & _
  117.  vbnewline & _
  118.  resultoutput
  119.  
  120.  
  121. '==This section provides the configuration information for the remote SMTP server.
  122. '==Normally you will only change the server name or IP.
  123. objMessage.Configuration.Fields.Item _
  124. ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
  125. 'Name or IP of Remote SMTP Server
  126. objMessage.Configuration.Fields.Item _
  127. ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = SMTPServer
  128. 'Server port (typically 25)
  129. objMessage.Configuration.Fields.Item _
  130. ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
  131. objMessage.Configuration.Fields.Update
  132. '==End remote SMTP server configuration section==
  133. objMessage.Send
  134.  
  135. End Sub
  136.  
  137. Function GetVBDate(wd)
  138.   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))
  139. End Function
  140.  
  141. sub Send_MGR_Email
  142. Set objMessage = CreateObject("CDO.Message")
  143. objMessage.Subject = "Account Expiry Report for " & dt
  144. objMessage.From = "AccountExpiryReport@ipacc.com"
  145. objMessage.To = subjto
  146. objMessage.TextBody = _
  147.  "!! Please read carefully !!" & vbnewline & _
  148.  "This report runs automatically every 2 weeks to alert the managers (as reported by HR)" & vbnewline & _
  149. "of contractors/vendors whose VPN accounts (remote access) are getting close to expiring.  An expired account" & vbnewline & _
  150. "will no longer have access to our systems and could be disruptive to completing projects for which they were contracted." & vbnewline & _
  151. "This is informing you that a user that may report to you has an account expiring in the next 19 days." & vbnewline & _
  152. "If you need to extend the account please submit a help desk ticket or if the account needs to be deleted" & vbnewline & _
  153. "please submit a ticket asking that the account be removed." & vbnewline & _
  154.  vbnewline & _
  155. "Please contact the Corporate Help Desk if you have any questions." & vbnewline & _
  156.  vbnewline & _
  157. "Thank you." & vbnewline & _
  158.  vbnewline & _
  159. "*** This is automatically generated email � please do not reply ***" & vbnewline & _
  160.  vbnewline & _
  161.  msgmessage
  162.  
  163.  
  164. '==This section provides the configuration information for the remote SMTP server.
  165. '==Normally you will only change the server name or IP.
  166. objMessage.Configuration.Fields.Item _
  167. ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
  168. 'Name or IP of Remote SMTP Server
  169. objMessage.Configuration.Fields.Item _
  170. ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = SMTPServer
  171. 'Server port (typically 25)
  172. objMessage.Configuration.Fields.Item _
  173. ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
  174. objMessage.Configuration.Fields.Update
  175. '==End remote SMTP server configuration section==
  176. objMessage.Send
  177.  
  178. End sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement