刪除Exchange Server IIS 15天日誌

刪除超過15天的IIS日誌服務器

IIS日誌文件默認存儲在IIS服務器的%SystemDrive%\inetpub\logs\LogFiles文件夾。
經過建立一個Windows任務計劃運行腳本,能夠自動化刪除日誌文件任務。可使用Windows Task Scheduler安排腳本在任什麼時候間運行。
腳本從Exchange刪除IIS日誌。
能夠改變IIS目錄。
Microsoft不支持第三方刪除工具工具

 

#Written by David Maugrion - ATOS - david.maugrion@atos.net
#change the d value to match your policy

$d=-15
$report = Get-ClientAccessServer | Where-object {Test-Connection -ComputerName $_.Name -Count 1 -Quiet} | Foreach-Object {
    $cas = $_.Name
    Write-Verbose "Making IIS connection to $cas" 
    ([adsi]"IIS://$cas/W3SVC").Children | Where-Object {$_.KeyType -eq 'IIsWebServer'} | Foreach-Object {
        New-Object -TypeName PSObject -Property @{
            #WebSite = $_.ServerComment[0]
            LogLocation = $_.LogFileDirectory[0]
            UncLogLocation = $_.LogFileDirectory[0] -replace "^(.)(.)","\\$cas\`$1$"
        }
    }
}


#display the results
$report

$report | Foreach-Object{
   
gci -Path $_.UncLogLocation -recurse -include *.log -Force | where -FilterScript {$_.LastWriteTime -le [System.DateTime]::Now.AddDays($d)} | Ri -Force -Confirm:$false

$t=(gci -Path $_.UncLogLocation -recurse -include *.log -Force | where -FilterScript {$_.LastWriteTime -le [System.DateTime]::Now.AddDays($d)}).Count
$gt=$gt+$t
}
if ($gt -gt 0) 
{Write-Host "$gt Log files deleted" -foregroundcolor yellow}
else
{Write-Host "No Log files deleted" -foregroundcolor yellow}
相關文章
相關標籤/搜索