Hi all
I am trying to finish this script which grabs info from a generated text file. The text file was generated using certutil. It's a list of all the user and computer certificates which are going to expire within 30 days. I have everything working correctly except the format of the email. Here's what's happening. I read the original text file generated by certutil. Grab the information I need using the inStr function. Write that infor to another text file. Pull the info from the new text file and send it to the users with the info regarding their certificates. This is what's working. There are 20 entries in the text file. I receive 20 emails (testing with my account) That's good. Here's what's not working. The only information (from variables in the script) that is being sent in the email is the certificate template info, all the other info is blank. Also I'm trying to use the instr function at the beginning to send to only users that have @ in the name. Anyway here's a sample email and the code. BTW all of the emai subjects are "No UserName"
Here's the code
I am trying to finish this script which grabs info from a generated text file. The text file was generated using certutil. It's a list of all the user and computer certificates which are going to expire within 30 days. I have everything working correctly except the format of the email. Here's what's happening. I read the original text file generated by certutil. Grab the information I need using the inStr function. Write that infor to another text file. Pull the info from the new text file and send it to the users with the info regarding their certificates. This is what's working. There are 20 entries in the text file. I receive 20 emails (testing with my account) That's good. Here's what's not working. The only information (from variables in the script) that is being sent in the email is the certificate template info, all the other info is blank. Also I'm trying to use the instr function at the beginning to send to only users that have @ in the name. Anyway here's a sample email and the code. BTW all of the emai subjects are "No UserName"
Code:
CertTest
Issued Request ID:
Certificate Expiration Date:
User Principal Name:
Certificate Template: "EFS"
Here's the code
Code:
'================================================
'
' NAME:
'
' AUTHOR: Gene Magerr
' EMAIL: genemagerr@hotmail.com
'
' COMMENT:
'
' You have a royalty-free right to use, modify, reproduce, and
' distribute this script file in any way you find useful, provided that
' you agree that the creator, owner above has no warranty, obligations,
' or liability for such use.
'
' VERSION HISTORY:
' 1.0 xx/xx/xxxx Initial release
'
'================================================
'Option Explicit
'================================================
' VARIABLE DECLARATIONS
'================================================
Dim objShell, objNetwork, objFSO
Set objShell = CreateObject("WScript.Shell")
Set objNetwork = WScript.CreateObject("WScript.Network")
Set objFSO = CreateObject("Scripting.FilesystemObject")
'================================================
' STATIC VARIABLE ASSIGNMENTS
'================================================
Const FOR_READING = 1, FOR_WRITING = 2, FOR_APPENDING = 8
'================================================
' MAIN SCRIPT CODE
'================================================
If Not objFSO.FileExists("D:\DATA\PKI\Expire\TempCert.txt") Then
objFSO.CreateTextFile("D:\DATA\PKI\Expire\TempCert.txt")
End If
Set objTempCert = objFSO.OpenTextFile("D:\DATA\PKI\Expire\TempCert.txt",2)
Set strCert = objFSO.OpenTextFile("D:\DATA\PKI\Expire\expiring_certificates.txt",1)
strArray = Split(strCert.ReadAll,vbCrLf)
For Each cert In strArray
If InStr(cert, "Issued Request ID:") Then
reqID = Trim(Split(cert,":")(1))
objTempCert.WriteLine "Issued Request ID: " & reqID
ElseIf InStr(cert, "Certificate Expiration Date:") Then
expDate = Trim(Split(cert,":")(1))
objTempCert.WriteLine "Certificate Expiration Date: " & expDate
ElseIf InStr(cert, "User Principal Name:") Then
userName = Trim(Split(cert,":")(1))
objTempCert.WriteLine "User Principal Name: " & userName
ElseIf InStr(cert, "Certificate Template:") Then
cerTemplate = Trim(Split(cert,":")(1))
objTempCert.WriteLine "Certificate Template: " & cerTemplate & vbCrLf
End If
reqID = "": expDate = "": userName = "": cerTemplate = ""
Next
strCert.Close
Set strCertSend = objFSO.OpenTextFile("D:\DATA\PKI\Expire\TempCert.txt",1)
strArraySend = Split(strCertSend.ReadAll,vbCrLf)
For Each certsend In strArraySend
If InStr(certsend, "User Principal Name:") Then
userName = Trim(Split(certsend,":")(1))
End If
Set objEmail = CreateObject("CDO.Message")
objEmail.From = "gmagerr@rand.org"
If InStr(userName, "@") <> True Then
objEmail.To = "gmagerr@rand.org"
objEmail.Subject = "No UserName"
Else
objEmail.To = "gmagerr@rand.org"
objEmail.Subject = "Cert Test"
End if
If InStr(certsend, "Issued Request ID:") Then
reqID = Trim(Split(certsend,":")(1))
ElseIf InStr(certsend, "Certificate Expiration Date:") Then
expDate = Trim(Split(certsend,":")(1))
ElseIf InStr(certsend, "User Principal Name:") Then
userName = Trim(Split(certsend,":")(1))
ElseIf InStr(certsend, "Certificate Template:") Then
cerTemplate = Trim(Split(certsend,":")(1))
objEmail.TextBody = objEmail.TextBody & ("CertTest") & vbCrLf
objEmail.TextBody = objEmail.TextBody & vbCrLf & "Issued Request ID: " & reqID
objEmail.TextBody = objEmail.TextBody & vbCrLf & "Certificate Expiration Date: " & expDate
objEmail.TextBody = objEmail.TextBody & vbCrLf & "User Principal Name: " & userName
objEmail.TextBody = objEmail.TextBody & vbCrLf & "Certificate Template: " & cerTemplate
objEmail.Configuration.Fields.Item ("[URL unfurl="true"]http://schemas.microsoft.com/cdo/configuration/sendusing")[/URL] = 2
objEmail.Configuration.Fields.Item ("[URL unfurl="true"]http://schemas.microsoft.com/cdo/configuration/smtpserver")[/URL] = "mail.rand.org"
objEmail.Configuration.Fields.Item ("[URL unfurl="true"]http://schemas.microsoft.com/cdo/configuration/smtpserverport")[/URL] = 25
objEmail.Configuration.Fields.Update
objEmail.Send
End If
reqID = "": expDate = "": userName = "": cerTemplate = ""
objEmail.TextBody = ""
Next
strCertSend.Close
'================================================
' SUBS AND FUNCTIONS
'================================================