I need script for file modify time check and if date older, file will be deleted and send report to my email :
$Now = Get-Date -Format "yyyy-MM-dd HH:mm:ss" $Logfile = "C:\dir\logs.txt" $File = "C:\dir\check_file_name.txt" $LastModidy=(Get-Item $File).LastWriteTime; $today = (Get-Date).AddMinutes(-30) if ($LastModidy -lt $today) { Write-Host "Status: Expired" Remove-Item -Path $File -Force -WhatIf "$Now File $File deleted." | Out-File -FilePath $Logfile -Append Send-MailMessage -To "ForMe" -From "FromSRV " -Subject "Error Msg Title" }else{ Write-Host "Status: OK" }