Deleting IIS Ex*.log files
I planning on doing some much needed house cleaning on Exchange (2003) and I have IIS Ex*.log files going back to 2005 on exchange located in the C:\WINDOWS\system32\LogFiles\W3SVC1 directory. I would like to keep the past month, so are they safe to delete, and/or is there a perfered way to do so?
April 11th, 2011 9:55pm

It is safe to delete them. However I alsways preffer to backup them and than delete for example using that simple script: #archive log files by month #script is used to archive log files by month #param $archiveName param ([int]$month, [int]$year) #param $path #$month = 8 #$year = 2010 if ($month -gt 0 -and $year -gt 0) { $path = "C:\inetpub\logs\LogFiles\W3SVC1" $zipPath = 'C:\"Program Files"\7-Zip\7z.exe' $files = (Get-ChildItem $path -Filter *.log | Where {$_.LastWriteTime.Month -eq $month -and $_.LastWriteTime.Year -eq $year}) $logs = "" $archiveName = "" if ($files -ne $null -and $files.Length -gt 0) { foreach ($file in $files) { #Write-Host $file.Name $file.LastWriteTime.Month $file.LastWriteTime.Year $archiveName = $file.Directory.Name $logs += "`"" + $file.FullName + "`" " } if ($logs -ne "") { $archiveName = $year.ToString() + '-' + $month.ToString() + '-' + $archiveName + '.7z' $cmd = "$zipPath a $path`\$archiveName $logs -mx9 > $path`\output.txt" #Write-Host $cmd Invoke-Expression $cmd $output = "$path`\output.txt" $line = Get-Content $output | select -Last 1 #Write-Host $line if ($line -eq "Everything is Ok") { foreach ($file in $files) { Write-Host $file.FullName Remove-Item $file.FullName } } } } } the script requires that you have 7zip installed on your machine, it accepts month and year as parametersWith kind regards Krystian Zieja http://www.projectnenvision.com Follow me on twitter My Blog
Free Windows Admin Tool Kit Click here and download it now
April 11th, 2011 10:02pm

Go ahead and delete them, This should be in praticse to delete old log files on regular basis. Anil
April 11th, 2011 11:14pm

Thanks Again.. You guys are great, and I will add this in my regular maintenance program! Dave
Free Windows Admin Tool Kit Click here and download it now
April 12th, 2011 12:47pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics