PowerShell清空IIS日志

来源:互联网 发布:mac可以玩使命召唤吗 编辑:程序博客网 时间:2024/06/08 19:17

通过Powershell可以很方便地清理IIS日志,今天获得了一个脚本,现在贴出来作为学习记录。

# Module: Powershell script to clean IIS log files Set-Executionpolicy RemoteSigned$days=-7 (Get-Variable Path).Options="ReadOnly"$Path="C:\inetpub\logs\LogFiles\W3SVC1"Write-Host "Removing IIS-logs keeping last" $days "days"CleanTempLogfiles($Path)function CleanTempLogfiles(){    param ($FilePath)    Set-Location $FilePath    Foreach ($File in Get-ChildItem -Path $FilePath)    {        if (!$File.PSIsContainerCopy)         {            if ($File.LastWriteTime -lt ($(Get-Date).Adddays($days)))             {                 remove-item -path $File -force                 Write-Host "Removed logfile: "  $File            }        }    } }
代码很简单,可以封装成函数使用。

0 0