I need to create a job (either windows batch or SQL Server Agent job) that will run a cmd command that checks a file creation date and then sends an email with that information. Is there a way to create a send email task to do that? The cmd command would be something like: dir /T:W "\networkfolder\" | findstr filename.csv And it would return the file creation date information. I want to have an email sent out with that information. Thanks
Asked
Active
Viewed 457 times
0
-
SSIS package would be your best bet. Or you could write a C# app and execute the .exe file from the job but the job agent would need access to the path you are storing the .exe file – Brad Nov 12 '18 at 17:06
1 Answers
0
SQL Server
You can use xp_cmdshell to run what ever command you want, and output the results.
Then, you'd use sp_send_dbmail to send the email based on what ever logic you want.
PowerShell
This seems to be the more logical choice, since SQL Server isn't needed at all. You can do something similar in a batch file.
Run what ever command you want in an IF()
statement to figure out the date, and then send an email based off the result.
IF(...){
Send-MailMessage -To "ME <me@domain.com>" -From "Server <server@domain.com>" -Subject "Some condition was met" -Body "some relevant info"
}

S3S
- 24,809
- 5
- 26
- 45