locked
Check for files older than 2 minutes and sends out notification if the file still exists RRS feed

  • Question

  • Hi, I am trying to write a script to monitor a folder 24/7 for new files and if the same file exists after 2 minutes then sends out gmail notification with file name.

    $path = '\\file-path' 

    $stats = 0 
    $msg = '' 
    $days = 0
    $hours = 0 
    $minutes = 2
    $files = @(Get-ChildItem -Recurse -Path $path -Include '*.*' | ?{ $_.LastWriteTime -lt (Get-Date).AddDays(-$days).AddHours(-$hours).AddMinutes(-$minutes) -and $_.psIsContainer -eq $false}) 
    if ($files -ne $null) { 
      $f_names = [System.String]::Join('|',$files) 
      $msg = 'Message: ' + $f_names 
      $stats = $files.Count 
    } else { 
      $msg = 'Message: 0 files exceed defined age' 

    Write-Host $msg 
    Write-Host "Statistic: $stats" 

    check the older folder for files less than 2 hours whose size is 0kb and sends out gmail notification.

    Get-ChildItem -Path C:\Users\kvavilapalli\Downloads\temp -Recurse -Include *.* | Where {$_.Length -eq 0} | Select-Object FullName



    • Edited by vavilapalli Tuesday, September 17, 2019 6:22 PM
    Tuesday, September 17, 2019 5:53 PM

All replies

  • This is how to get the files required:

    Get-ChildItem c:\folder\* -Recurse |
    	Where-Object{
    		$_.Length -eq 0 -and
    		$_.LastWriteTime -lt [datetime]::Now.AddMinutes(-2)
    	}


    \_(ツ)_/

    Tuesday, September 17, 2019 6:51 PM
  • Hi,

    Was your issue resolved?

    If you resolved it using our solution, please "mark it as answer" to help other community members find the helpful reply quickly.

    If you resolve it using your own solution, please share your experience and solution here. It will be very beneficial for other community members who have similar questions.

    If no, please reply and tell us the current situation in order to provide further help.

    Best Regards,

    Lee


    Just do it.

    Friday, October 4, 2019 8:03 AM