Web Search


Site Search


Youngevity Essential Life Sciences

Independent Representative


Ultimate Health and Wellness starts with the 90 Essential Nutrients

Are You Getting Yours?


Smart FX

Contrary to popular belief, it isnt actually the FISH that is so good for our mind and body, but the essential fatty acids (EFAs), or Omega-3s, that are found IN the fish.

$42.10*


HairSkin Nails

Youngevitys Hair, Skin & Nails Formula nourishes and strengthens your hair, skin and nails, beautifying from the inside out!

$34.30*


Plant Derived Minerals

The colloidal mineral supplement to which all others compare. A liquid concentrate of 19,000 mg of approximately 77 minerals from prehistoric plants.

$27.15*


Selenium

Selenium is one of the most documented and widely studied trace elements known.

$34.30*


*prices in USD & subject to change
Join the Youngevity Team

Monitoring Logfiles with Powershell

Microsoft includes quite a few Powershell "cmdlets" to easily gather info and perform actions against Windows Operating Systems. One of these "cmdlets" is called Get-EventLog and allows you to easily get the entries within a System's Event Logs. Upon playing around with this cmdlet I found that I could easily create a website that I could use to easily go through all the servers logfiles that I help maintain.

This article will step you through setting up what I created within your network to aid in maintaining your Windows Servers. You can view an example page of what this looks like here, note that I simply used the same machine 6 times, but you will get the idea of what the results look like.

Getting & Formatting the Logfiles

The first step is to actually get the logfiles from all the servers you want to monitor. To do this I create the following script. What this script does is:

  1. Put's the last 24 hours of log entries as an HTML Table and put it into a temporary file
  2. Strips all the "heading" tags in the HTML file, along with the last few tags that are not needed.
  3. Add a few CSS style markers to the table
  4. The resulting file (which should only include everything within the <table> tags) is written to
    the C:\Inetpub\wwwroot\serverlogs directory

View the get-logfiles.ps1 script here, it is also included with the Logfile Monitoring Zip File.


$computers = @("Server1","Server2","Server3")

ForEach ($computer in $computers) {

Get-EventLog Application -EntryType Error,Warning -ComputerName $computer -after (get-date).AddHours(-24) | select TimeWritten,EntryType,Source,EventID,Message | ConvertTo-Html -As Table > C:\Inetpub\wwwroot\serverlogs\$computer-applog-tmp.html
(Get-Content C:\Inetpub\wwwroot\serverlogs\$computer-applog-tmp.html) | ? {(1..5) -notcontains $_.ReadCount} | Foreach-Object {$_ -replace "</body></html>", " "} | Foreach-Object {$_ -replace "<table>", "<table id=$computer-applog style=display:none>"} |Set-Content C:\Inetpub\wwwroot\serverlogs\$computer-applog.html

Get-EventLog System -EntryType Error,Warning -ComputerName $computer -after (get-date).AddHours(-24) | select TimeWritten,EntryType,Source,EventID,Message | ConvertTo-Html -As Table > C:\Inetpub\wwwroot\serverlogs\$computer-syslog-tmp.html
(Get-Content C:\Inetpub\wwwroot\serverlogs\$computer-syslog-tmp.html) | ? {(1..5) -notcontains $_.ReadCount} | Foreach-Object {$_ -replace "</body></html>", " "} | Foreach-Object {$_ -replace "<table>", "<table id=$computer-syslog style=display:none>"} | Set-Content C:\Inetpub\wwwroot\serverlogs\$computer-syslog.html
 
 }

If you are attempting to run this over a slower WAN connection, this script may "timeout" and never complete. If you are trying to get logfiles from remote servers/workstations, create a scheduled task on a remote computer to gather the scripts for that network, then at the end of the script perform a copy to the server/workstation you will host the Web Frontend on, for instance, use the above script, adjust the output directory, then simply add the following command at the end of it:

copy c:\logs\*log.html \\servername\c$\inetpub\wwwroot\serverlogs

You can view the remote_get-logfiles.ps1 script here, it is also included with the Logfile Monitoring Zip File.

Now that you have the needed html files for each server's app and system log, next I will show you how to setup webpages to easily view the logfiles.

Next: Including the Logfiles in a Website