Jump to content

Folder Monitor


njcltd
 Share

Recommended Posts

Hi,

I would like to have a folder monitor, basically I have a folder (or several folders) that I need to monitor that the files in the folder and receive alerts for the following.

- files are older than X days
- over X number of files in the folder

 

Please advise if this is possible currently of if this will require development, if this can be accomplished with a script then some pointers would be useful, ideally this would run at the same rate as other aspects of the system, but it could also be a daily/hourly check as I understand it could consume time processing!

 

Link to comment
Share on other sites

  • Staff

Hi,

try to run these scripts:

Check if folder contines files older than 10 days.

$fullPath = "path to the folder"
$days = 10 # files older than 10 days

$files = @(get-childitem $fullpath -include *.* -recurse | where {($_.LastWriteTime -lt (Get-Date).AddDays(-$days)) -and ($_.psIsContainer -eq $false)})
if($files.length -gt 0){exit 1}
else{exit 0}

Check if folder contains more than 5 files

$fullPath = "path to the folder"
$count = 5 # check if folder containes more than 5 files

$files = @(get-childitem $fullpath)
if($files.Count -gt $count){exit 1}
else{exit 0}

 

Link to comment
Share on other sites

Thanks Chris, the script works fine, I can add some output to them, but it seems they require running manually? Is there a way to have scripts run at the same interval as other test, at the very least I would need to check hourly?

it would be great if this could be added in a similar format to the SSL so that multiple folders could be added with Alert times from 1 minute, happy to discus this offline.

I could do an automation script but there is not an option less than daily.

Many Thanks

Link to comment
Share on other sites

  • 2 years later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...