Script find wildcard in a file name and if found send email

July 25, 2015 at 13:22:40
Specs: Server 2008 R2, 3.2 Ghz / 16GB
I have been trying to find a script that will search sub directories of D:\Backups\ for a .spi file with _vm_ in its file name (eg: 123456_vm_789.spi). If a file with _vm_ in its file name is found I would like it to send an email to someone@xyzcompany.com and in the subject line have something like "VM Files Detected on ServerHostName" in the message body display the path of the file found (eg: D:\Backups\123456_vm_789.spi Found)

The files are randomly generated with _vm_ being the only common thing or string.

If no file exist then exit and no email will be sent.

I have tried taking bits and pieces from other scripts but cannot find a working combination.

Thank you


See More: Script find wildcard in a file name and if found send email

Report •

#1
July 25, 2015 at 23:08:37
What's the syntax of your emailer?

=====================

M2 Get custom script or take private lessons


Report •

#2
July 26, 2015 at 00:53:52
I was hoping to incorporate existing code that works for other scripts I have for example


'**********************************************************************
'E-MAIL ADDRESS TO SEND ALERTS TO (UP 100 Email address can be added)
'**********************************************************************
AlertEmailAddress(0) = "help@ourcompany.com"

'**********************************************************************
'EMAIL SETTINGS
'**********************************************************************
AlertFromAddress = " (noreply@ourcompany.com)"
EmailReplyToAddress = "noreply@ourcompany.com"

'**********************************************************************
'SMTP SETTINGS
'**********************************************************************
SMTPServerPort = 587
SMTPServer = "mail.ourcompany.com"
SMTPUserName = "noreply@ourcompany.com" 'Leave Blank to disable SMTP Auth.
SMTPPassword = "**********"




'######################################################################
'ERROR Handling
'######################################################################
'######################################################################
'Build Message Depending on overall status
'######################################################################

If RoboCopySuccessful Then
AlertSubject = "Company A Successful Backup"
AlertBody = "Here are the result of " & servername & " Backup:" & vbNewLine & vbnewline
End If

If RobocopyWarning Then
AlertSubject = "Company A Backup With Some Warnings"
AlertBody = "One or more of the backup sets had warnings on " & servername & _
". Below are the details:" & vbNewLine & vbnewline
End If

If RobocopyError Then
AlertSubject = "Company A BACKUP ERRORS"
AlertBody = "One or more of the backup sets had ERRORS on " & servername & _
". Below are the details:" & vbNewLine & vbnewline & _
"Please forward this backup notification to help@ourcompany.net:" & vbNewLine & vbNewLine
End If

'######################################################################
'Zip attachments
'######################################################################
For ZipAttach = 0 To NumberOfCommandsProcessed
ZipCommand = ZipCommand & Attachment(ZipAttach) & " "
Next
ZipReturnCode = objshell.Run(ZipCommand,,True)
if ZipReturnCode > 0 then
Set myErrorLog = CreateObject("Scripting.FileSystemObject")
Set WriteFile = myErrorLog.OpenTextFile("C:\Scripts\Logs\Script_Errors.txt", 8, True)
WriteFile.WriteLine("--------------------------")
WriteFile.WriteLine("On " & Date() & " at " & Time() & " the " & BackupName & " backup of " & ServerName & " server crashed." )
WriteFile.WriteLine("Zip command returned: " & ZipReturnCode)
WriteFile.WriteLine("Zip command executed was: " & ZipCommand)
WriteFile.WriteLine("--------------------------")
WriteFile.Close
End If

'######################################################################
'Process Arrays to Build detailed message subject
'######################################################################
For AlertIndex = 0 To NumberOfCommandsProcessed
If InStr(UCase(BackupCommandLine(AlertIndex)), "ROBOCOPY") then
' Handle error codes for Robocopy
Select Case RoboCopyReturnCode(alertindex)
Case 0,1,2,3
AlertText1 = "Successful"
Case 4,5,6,7,8,9,10,11,12,13,14,15
AlertText1 = "WARNING!"
Case Else
AlertText1 = "ERROR!"
End Select
Else
' Handle commands that weren't Robocopy
Select Case RoboCopyReturnCode(alertindex)
Case 0
AlertText1 = "Successful"
Case 1
AlertText1 = "ERROR!"
Case Else
AlertText1 = "WARNING!"
End Select
End If

AlertBody = AlertBody & "-----" & BackupCommandDescription(AlertIndex) & "-----" & vbCrLf & _
"Status: " & AlertText1 & " Code " & RoboCopyReturnCode(AlertIndex) & vbCrLf & _
"Backup Started: " & BackupStartTime(AlertIndex) & vbCrLf &_
"Backup Completed: " & BackupCompleteTime(AlertIndex) & vbCrLf &_
"Log File: " & Attachment(alertIndex) & vbNewLine & vbnewline
Next

'######################################################################
'Create TO: List
'######################################################################
For AlertEmail = 0 To 100
If AlertEmailAddress(alertemail) = "" Then Exit For
If emailaddressTO = "" Then
emailaddressto = AlertEmailAddress(alertemail)
Else
emailaddressto = emailaddressto & "; " & AlertEmailAddress(alertemail)
End if
Next

objEmail.From = AlertFromAddress
objEmail.To = emailaddressto
objEmail.Subject = AlertSubject
objEmail.Textbody = Alertbody
If emailreplytoaddress <> "" Then objemail.ReplyTo = EmailReplyToAddress

'Verify and attach Zip file
'attach logs only if there were problems
'If Not RoboCopySuccessful Then
Set objFSO = CreateObject("Scripting.FileSystemObject")
If objFSO.FileExists(ZipAttachFile) then
objemail.AddAttachment "File:////" & ZipAttachFile
else
objEmail.Textbody = "Warning! Zipped Log Files could not be located to attach to this email" & chr(13) & " - missing zip file should have been at: " & ZipAttachFile & chr(13) & chr(13) & Alertbody
End If
'End If

objEmail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
objEmail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver") = SMTPServer
objEmail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = SMTPServerPort
If SMTPUserName <> "" Then objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
objemail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusername") = SMTPUserName
objemail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendpassword") = SMTPPassword
objEmail.Configuration.Fields.Update
objEmail.Send


If DisableMappingDrives = False Then
wsnetwork.RemoveNetworkDrive MapNetworkDriveLetter,True
End if


Report •
Related Solutions


Ask Question