<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title> &#187; Event Log</title>
	<atom:link href="http://risualblogs.com/blog/tag/event-log/feed/" rel="self" type="application/rss+xml" />
	<link>http://risualblogs.com/blog</link>
	<description></description>
	<lastBuildDate>Fri, 18 May 2012 16:31:58 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.3</generator>
		<item>
		<title>Archiving Event Logs</title>
		<link>http://consulting.risualblogs.com/blog/2010/06/03/archiving-event-logs/</link>
		<comments>http://consulting.risualblogs.com/blog/2010/06/03/archiving-event-logs/#comments</comments>
		<pubDate>Thu, 03 Jun 2010 10:33:34 +0000</pubDate>
		<dc:creator>Rob</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Event Log]]></category>
		<category><![CDATA[Powershell]]></category>

		<guid isPermaLink="false">http://2.137</guid>
		<description><![CDATA[As part of a recent engagement I was asked to implement a solution to automatically export &#38; archive System and Security logs from servers to a central location, the requirements were: Nightly time stamped archive of Security and System event logs to a central location Clear the local log once the archive has been successfully [...]


No related posts.

Related posts brought to you by <a href='http://yarpp.org'>Yet Another Related Posts Plugin</a>.]]></description>
			<content:encoded><![CDATA[<p>As part of a recent engagement I was asked to implement a solution to automatically export &amp; archive System and Security logs from servers to a central location, the requirements were:</p>
<ul>
<li>Nightly time stamped archive of Security and System event logs to a central location</li>
<li>Clear the local log once the archive has been successfully taken</li>
</ul>
<p>I put together the following PowerShell script to achieve the above:</p>
<p>&#160;</p>
<p><font face="Courier">$locallocation = &quot;c:logs&quot;     <br />$remotelocation = &quot;\fileserverEventLogs&quot;      <br />$localmachine = $env:computername </font></p>
<p><font face="Courier">$evtlgs = Get-WMIObject -Class Win32_NTEventLogFile -Computer $localmachine     <br />foreach ($log in $evtlgs)      <br />&#160;&#160;&#160; {      <br />&#160;&#160;&#160; if ($log.LogFileName -eq &quot;System&quot; -or $log.LogFileName -eq &quot;Security&quot;)      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; {      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; $timestamp = get-date -f yyyyMMddHHmmss      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; $path = $log.LogFileName + $timestamp      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; $store = $locallocation+$path+&quot;.evt&quot;      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; $backup = ($log.backupeventlog($store)).ReturnValue      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; if($backup -eq 0)      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; {      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; $log.ClearEventLog() | out-null      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; }&#160;&#160;&#160;&#160;&#160; <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; move-item $locallocation* $remotelocation$localmachine      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; }      <br />&#160;&#160;&#160; }</font></p>
<p>The above script is executed by a Scheduled Task (which on another note are brilliant on Server 2008), the lines you’re interested in are the top 2 lines which configure a local location to write the log out to and the remote location to move the log to once it has been written.&#160; I ran this script using a service account which has permission to write to the local and remote locations.&#160; </p>
<p>If you wanted a different selection of logs to be archived you would adjust the </p>
<p align="center"><font face="Courier">if ($log.LogFileName -eq &quot;System&quot; -or $log.LogFileName -eq &quot;Security&quot;)</font></p>
<p>line to suit your requirements.</p>
<p>In our requirement the logs had to be archived daily, this was simply achieved by configuring task scheduler to run once per day at the desired time, no code changes are required.&#160; </p>
<p>The requirement for only clearing the local log if the export was successful is met by checking the exit code form the backup, if this wasn’t 0 then the log wont be cleared.</p>


<p>No related posts.</p>
<p>Related posts brought to you by <a href='http://yarpp.org'>Yet Another Related Posts Plugin</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://consulting.risualblogs.com/blog/2010/06/03/archiving-event-logs/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

