Link to home
Start Free TrialLog in
Avatar of Thor2923
Thor2923Flag for United States of America

asked on

Need to modify my powershell script to create event logs or perhaps a time stamp

I got some help a few weeks ago and now use the following scrpt to clean up old .dat files that build up on my sharepoint server. The script works great and I am still thankful for the help I received, but my boss is hoping I can modify it to create event logs when it begins and ends or even a timestamp so we can use our network monitor to see how long it actually runs and be alerted if it stops running for some reason. I run this from a .bat file and it is scheduled to run in SCHEDULED TASKS. Everything runs fine, we just want to be able to monitor how long it takes and be alearted if it does not run. We were thinking we could monitor the event viewer and if a certain message does not appear we get alerted. All advice welcome..thanks

$Path = "D:\WSS_Files\data_realtime_archive\DataVolume\Farm(PTI-SQL#SHAREPOINT_CONFIG_FARM1)\http#80#processing\#"
gci $path -filter *.dat -recurse | ?{$_.lastwritetime -lt ((get-date).adddays(-60))} | Remove-Item -recurse -force
Avatar of Dale Harris
Dale Harris
Flag of United States of America image

What if you have it email you every time it finishes?  Set it to kick off at 9AM (or whatever) and then when you get the email, you know two things: how long it ran and that it's done.  If you don't get one, it didn't kick off.

http://blogs.msdn.com/b/powershell/archive/2009/10/30/sending-automated-emails-with-send-mailmessage-convertto-html-and-the-powershellpack-s-taskscheduler-module.aspx

HTH,

Dale Harris
Avatar of Thor2923

ASKER

interesting idea, I will run it by my boss....I am still hoping this job to create some kind of event log though....thanks
ASKER CERTIFIED SOLUTION
Avatar of Dale Harris
Dale Harris
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
your time commands look like they are going to work. I was able to add your commands and copy and paste my script into a powershell window and after running it reported how many seconds it took. The next step would be to get this to create the output in a file if I call the PS1 from a BAT file. Do you know if there is an easy modification for that?? BTW the event comman looks great too, I am playing with that now
You can hardcode the output:

"Your script took a total of $($Difference.seconds) seconds to run" > "C:\TestTimer.txt"

Good luck!

DH
All your advice is working out perfectly!!! I have got much more interested and learned a lot about POWERSHELL from these few posts...THANKS