我在脚本中加入自动识别Exchange安装目录,而不用手动输入。另外该脚本只适用于Exchange 2013版本服务。
脚本内容如下:
---------------------------------脚本开始,将脚本内容另存为.ps1----------------------------------------------
Set-Executionpolicy RemoteSigned
$days=0
$IISLogPath="C:\inetpub\logs\LogFiles\"
$exinstallpath=$env:ExchangeInstallPath
$ExchangeLoggingPath="$exinstallpath\Logging\"
$ETLLoggingPath="$exinstallpath\Bin\Search\Ceres\Diagnostics\ETLTraces\"
$ETLLoggingPath2="$exinstallpath\Bin\Search\Ceres\Diagnostics\Logs"
Function CleanLogfiles($TargetFolder)
{
if (Test-Path $TargetFolder) {
$Now = Get-Date
$LastWrite = $Now.AddDays(-$days)
$Files = Get-ChildItem $TargetFolder -Include *.log,*.blg, *.etl, *.txt –Recurse –Force | Where {$_.LastWriteTime -le "$LastWrite"}
foreach ($File in $Files)
{Write-Host "Deleting file $File" -ForegroundColor "white"; Remove-Item $File -ErrorAction SilentlyContinue | out-null}
}
Else {
Write-Host "The folder $TargetFolder doesn't exist! Check the folder path!" -ForegroundColor "white"
}
}
CleanLogfiles($IISLogPath)
CleanLogfiles($ExchangeLoggingPath)
CleanLogfiles($ETLLoggingPath)
CleanLogfiles($ETLLoggingPath2)
---------------------------------------------------------脚本结束-----------------------------------------------------------------
本文转自 jialt 51CTO博客,原文链接:http://blog.51cto.com/jialt/1770722