Script to run as task check file modified date and send email RRS feed

  • Question

  • I need to run a scheduled task that will trigger at 7am daily and search a folder for any files that have a modified date that’s changed in the last day or 24 hours.  I’m stuck on whether what I’ve done so far is the best way to do this check and also I’m not sure how to get this to email out a file with the list of file or files that have changed in the last 24 hours. I don’t think the FileSystemChecker is worth the amount of time it seems to get that running as I’ve read it can be troublesome.  I’m trying to do something that just looks for files with a modified date that’s changed.  I don’t have to look for deleted files or added files email the folder. If nothing has changed then I need to send the email to a different group of folks than I do if there are files that changed. I’m stuck on how to do the email part.  The other part I’m stuck on is getting this to accept a unc path so I can run the task from another server.

    Get-Item C:\folder1\folder2\*.* | Foreach

    { $LastUpdateTime=$_.LastWriteTime


    if (($TimeNow - $LastUpdateTime).totalhours -le 24)

    {Write-Host "These files were modified in the last 24 hours "$_.Name }


    { Write-Host "There were no files modified in the last 24 hours" } }

    • Edited by PatC16 Thursday, April 23, 2020 3:53 AM Code
    Thursday, April 23, 2020 2:52 AM

All replies