Compare file creation date with current date and send email

Hi Experts,

I used below script to create DFSR health check files and saved those files to a shared drive. Now i need to send the latest log files to my email ID daily. Could someone help me with posershell code for sending the latest created file from a folder ?

I used below script to create heath check logs.

@echo off



set PARSEARG="eol=; tokens=1,2,3,4* delims=/, "
for /F %PARSEARG% %%i in (%CURRDATE%) Do SET DDMMYYYY=%%j-%%k-%%l

set PARSEARG="eol=; tokens=1,2,3* delims=:, "
for /F %PARSEARG% %%i in (%CURRTIME%) Do Set HHMM=%%i%%j%%k

set RG1_Report=\DC001\SYSVOL\DC001-%DDMMYYYY%-%HHMM%.html

@echo on

dfsradmin health new /rgname:“Domain System Volume” /\DC001 / /ReportName:\\DFSRHealthCheck\ASIA-DFSR_Health_Check_Report-%DDMMYYYY%-%HHMM%.html

echo RG1 %RG1Report% > %TEMP%\healthMessageBody.txt

For sending an email, use the Send-MailMessage cmdlet (run Get-Help Send-MailMessage -Full to learn about its options). I’m not sure which file you want to send, but here’s a generic example for finding the newest file in a folder:

$folder = 'c:\path\to\something\'

Get-ChildItem -Path $folder |
Where-Object { $_.PSIsContainer -eq $false } |
Sort-Object -Descending -Property LastWriteTime |
Select-Object -First 1