Below script should check if files have been created today and send an email to one of our users.
The problem is that I can't send more than one value in the body. I need to remove "File" from body to get the email out. Also there is one email for each file. I would rewrite it to send one mail with all files listed with dates.
@echo off
setlocal enabledelayedexpansion
echo Files changed today %date%
FOR %%A IN (*.*) DO (
set tf=%%~tA
set fd=!tf:~0,10!
if !fd!==%date% (
powershell -ExecutionPolicy ByPass -Command Send-MailMessage ^
-SmtpServer this.server.com ^
-To [email protected] ^
-From [email protected] ^
-Subject Updated^
-Body "%%A File"
)
)
So i actually got this working with some heavy googeling (even went to page 3 at one point)
This is my "Check files in folder and send email with whats new and whats old"
@echo off
setlocal enabledelayedexpansion
echo Files changed today %date%
FOR %%A IN (*.*) DO (
set tf=%%~tA
set fd=!tf:~0,10!
if !fd!==%date% (
set "file=!file! <br> %%A !tf!"
)
if NOT !fd!==%date% (
set "old=!old! <br> %%A !tf!"
)
)
set "file=!file!
set "old=!old!
set "today=<b>New today:</b> %file%"
set "older=<b>Older files</b> %old%"
set "body=!today! <br><br> !older!"
powershell -ExecutionPolicy ByPass -Command Send-MailMessage -BodyAsHtml^
-SmtpServer yourserver.com^
-To [email protected] ^
-From [email protected] ^
-Subject Updated^
-Body '!body!'