Solved

Event Logs (Application, System, Security event logs) script for Windows Server 2008 R2

Posted on 2013-06-18
9
3,752 Views
Last Modified: 2013-08-15
I need a good event log script that will work on my new servers (Windows server 2008 r2). The event log script I used for my old Windows Server 2003 does not work properly on Windows Server 2008 r2. Just need to automatically save and clear the server event logs (application, system and security) to a specific location monthly.
0
Comment
Question by:jslaught
  • 3
  • 2
  • 2
  • +2
9 Comments
 
LVL 5

Expert Comment

by:AbhishekJha
ID: 39258750
0
 
LVL 16

Expert Comment

by:gurutc
ID: 39258912
You can also use Sysinternals psloglist in a task.  I use it to catch my rapidly turning over Security Log events every 5 minutes:

d:
cd \locks

psloglist /accepteula \\dc1,dc2 -i 4767,4771,1625,4772,4724,4740 security -s -m 10 >testdc1.txt
psloglist /accepteula \\dc1,dc2 -i 4298 application -s -m 18 >>testdc1.txt

Set CURRDATE=CURRDATE.TMP
Set CURRTIME=CURRTIME.TMP

DATE /T > %CURRDATE%
TIME /T > %CURRTIME%

Set PARSEARG="eol=; tokens=1,2,3,4* delims=/, "
For /F %PARSEARG% %%i in (%CURRDATE%) Do SET YYYYMMDD=%%l%%k%%j

Set PARSEARG="eol=; tokens=1,2,3* delims=:, "
For /F %PARSEARG% %%i in (%CURRTIME%) Do Set HHMM=%%i%%j%%k

rem Echo RENAME %1 %1_%YYYYMMDD%%HHMM%
RENAME testdc1.txt  %YYYYMMDD%%HHMM%.txt

move d:\locks\*.txt d:\dsdata\locklogs

This works to capture the log data.  I just set the logs to overwrite old events.
- gurutc
0
 
LVL 5

Expert Comment

by:Pankaj_401
ID: 39258944
It seems like most people don't know about this feature, but Windows will rotate the log files automatically if so-configured. Look for "AutoBackupLogFiles" in this file.

You can configure this on a server-for-server basis, but that's tedious for a large number of servers. I created an Administrative Template to set this on server computers, and then scripted a startup script to add a scheduled task to periodically pick up, ZIP, and move the log files to a retention location. It worked really well, and was cheap!

http://mx02.wellbury.com/misc/EventLogPolicy.adm

for more help take a look

http://msdn.microsoft.com/en-us/library/aa363648(VS.85).aspx
0
 
LVL 16

Expert Comment

by:gurutc
ID: 39259124
Good post, but our log files turn over so fast that we only grab the events we care about.  Psloglist will hit all our DCs from one DC.  Not saying the autobackuplogfiles isn't a good idea, but we'd use gigs of space per day at the rate our logs fill.

- gurutc
0
Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

 
LVL 15

Accepted Solution

by:
ZabagaR earned 100 total points
ID: 39266673
Windows 2008 R2 has a built in command WEVTUTIL.EXE for this.
Make a windows scheduled task that runs the 1st of every month using WEVTUTIL.EXE

command syntax for clearing a log:
wevtutil cl <LogName> [/bu: <backup_file_name>]

If you wanted to clear and save the application log, system and security logs:

wevtutil.exe cl Application /bu:C:\logs\applog.evtx
wevtutil.exe cl System /bu:C:\logs\syslog.evtx
wevtutil.exe cl Security /bu:C:\logs\seclog.evtx

Schedule the 3-line batch script to run once per month.
0
 

Author Comment

by:jslaught
ID: 39267132
WEVTUTIL.EXE works great in a command prompt. Tried to run the 3-lines in a .bat file manually before putting them in and nothing happens? What am I doing wrong?
0
 
LVL 15

Expert Comment

by:ZabagaR
ID: 39267163
I'm not sure. I put the 3 lines in "test.bat" then double-clicked on it.  It worked fine for me.
Put a PAUSE statement at the end of the 3 lines so you can see what it did or didn't do.
0
 

Author Comment

by:jslaught
ID: 39287102
I'm getting an "access denied" error message when running the .bat with a PAUSE statement. Trying to troubleshoot it when I have a chance unless you have suggestions.
0
 

Author Closing Comment

by:jslaught
ID: 39412968
Was able to make the suggestion from the expert work finally. I had to run the wevtutil.exe commands as an admin to make it work via a .bat file through the command line and through task scheduler. I even researched and found out how to append the current date to the wevtutil.exe command:

example:

wevtutil.exe cl application /bu:\\c:\temp\application_%Date:~4,2%-Date:~7,2%.evtx

Thanks for the assistance!
0

Featured Post

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Join Greg Farro and Ethan Banks from Packet Pushers (http://packetpushers.net/podcast/podcasts/pq-show-93-smart-network-monitoring-paessler-sponsored/) and Greg Ross from Paessler (https://www.paessler.com/prtg) for a discussion about smart network …
ADCs have gained traction within the last decade, largely due to increased demand for legacy load balancing appliances to handle more advanced application delivery requirements and improve application performance.
This tutorial will give a short introduction and overview of Backup Exec 2012 and how to navigate and perform basic functions. Click on the Backup Exec button in the upper left corner. From here, are global settings for the application such as conne…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

896 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now