Quick Tip: Powershell snippet to alert on filesize growth

I had a request from a colleague today whether we could monitor a file and alert him if it grows above a certain size.

The context around this request involves an old, legacy process that calls an Access db file and automatically runs some statistics scripts which are then fed into a SQL database.

Sounds awful I know, but the author is long gone and the workflow hasn’t been transposed elsewhere yet. Every now and then, for some reason the file size of the mdf grows from the usual ~~700MB to the maximum 2GB due to some corruption.  At which time it gets restored and it works for a while.   Yeah, I get it, it’s awful !

Anyhow, this corruption happens infrequently and can go unnoticed. So this little snippet checks the file size, and if it’s over .5GB, sends an email to the user so they can take action.

I’ve no doubt I’ll use this somewhere else sometime, so here it is for posterity !

Change the $targetFile  and the growth tolerance (here 1.5) and email details as required save as a scheduled task.

When the trigger size is exceeded, the following email is despatched.

19-05-2015 10-14-51 PM





2 thoughts on “Quick Tip: Powershell snippet to alert on filesize growth

    1. Hey Ashley, thanks, sorry I missed your comment.
      You can just change the “1GB” to “1MB” on line 2, then the condition on line 4.
      HTH, Brett

Leave a Reply

Your email address will not be published. Required fields are marked *