Saturday, November 9, 2013

MDT Centralized Log Cleanup

I helped a friend a while back setup an MDT 2012 instance for a client of his. They are a small shop with a single IT person. Shortly after MDT became stable, their IT person left, leaving the office manager to set up machines. Lets just say MDT made her a happy camper until they got another IT person. In helping my friend diagnose the occasional problem I would ask him for logs and in some cases it was hard for him to obtain them as the systems ran off to the field and what not. Luckily MDT has a feature to handle this by putting one of these two lines in your customsettings.ini etc. The first will copy the logs to a network location when the system is deployed and the second will do it live during the image process.


I put them under MDT$/Logs (I use this share name vs the default DeploymentShare$ share) but they can go to any UNC path on the network that the MDT account can access. It will create a sub folder and put BDD.Log etc in it. Andrew Barnes has a great article on it.

As we quickly found, the folder started filling up so I gave him this simple shell script to keep it clean. Its ran as a scheduled task at 5AM each day to delete any logs older then 60 days. Change /P to the local path of the logs and /D to the days to delete, note the negative number.

 ::Written by Kevin Fason  
 :: This simple script will clean the MDT Logs folder of logs older then 60 days.  
 :: V1.0  
 ::  04.09.2013  
 ForFiles /P "D:\MDT\DeploymentShare\Logs" /D -60 /C "CMD /C if @ISDIR==TRUE echo RD /Q @FILE &RD /Q /S @FILE"  

It can be run directly within the scheduled task but I did it in a shell script so its easier to update.

No comments:

Post a Comment