Link to home
Start Free TrialLog in
Avatar of santoshmotwani
santoshmotwaniFlag for Australia

asked on

Powershell script to notify only new files

Hi Experts,

I have a production server executing files continuously . Sometimes i get files which are not in proper format hence they are not processed and they stay in there forever. I would like to have a script that will run every 5 mins on a specific folder to to check for newer files . I would like to have only new files as these files contains reason for failures. I would like file name to be sent via email.


This question is a followup of https://www.experts-exchange.com/questions/26895555/Powershell-script-to-notify-files-older-than-10-mins.html
Avatar of prashanthd
prashanthd
Flag of India image

I am a little confused, what was missing in the earlier solution/what is the additional functionality required?

regards
Prashanth

Avatar of santoshmotwani

ASKER

in this script i only want to email new files ... does not matter if they stay there for months.

this folder actually contain logs ... as soon as something stops working a new text file is generated in this folder . I want whenever that file is generated it should be sent via email.

Thnx for help
How often will you be scheduling the script to run?

regards
Prashanth
ASKER CERTIFIED SOLUTION
Avatar of rwskas
rwskas
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
thanks for your help.

Thats exactly what i wanted
@rwskas

If i add another email address , it does not send attachments.....

Can you please help
Can i please make a change, that it should only send email if there is a new file.
Can you post what you have changed? It should work that only a new file is emailed.
To add additional email addresses you should be doing:
$emailto = "someemail@domain.com, anotheremail@domain.com"
@rwskas :

The script is working fine , it works fine for additional email as well.

But what i want is not to send blank emails, at this moment it is sending blank emails because of no new files. I want it to send a email only when a new file is created.

Thanks for your help
Modified piece attached should take care of that - sorry I overlooked it.
If ($NewFiles) {
Foreach ($NewFile in $NewFiles) {
        $FileName = $NewFile.FullName
        Email $NewFile
        Add-Content $LogFile $FileName
}
}

Open in new window

Thnx mate !!!!