Source Code and Samples

Wednesday, 14 February 2007

Archive and pack IIS log files

Description

Archive and pack IIS log files.

Source Code

$WinRar = "C:\Program Files\WinRAR\rar"
$TodaysLogFile = get-date -Uformat %y%m%d
$TodaysLogFile = "ex$TodaysLogFile.log"
$LogFiles = ls *.log
if ($LogFiles) {
foreach ($File in $LogFiles) {
$FileName = $File.Name
if ($FileName -ne $TodaysLogFile) {
echo "Compressing $FileName"
&$WinRar m "$FileName.rar" $FileName
}
}
}

No comments: