批量清除Exchange 2013服务器上的日志
2016-05-06 13:49
726 查看
我们都知道Exchange 2013服务器上会定期产生很大的日志(例如:Diagnostic Logs (Health Manager) 、ETL Files、IIS Logs、HTTP Proxy Logs)。这些日志如果不定期删除,将会一直保留下来,这样会导致服务器磁盘空间不断减小,需要Exchange管理员定期对日志文件进行删除。手动删除操作繁琐,下面介绍一个自己改造后的脚本给大家。微软官网也有类似的脚本可以参考:http://social.technet.microsoft.com/wiki/contents/articles/31117.exchange-2013-logging-clear-out-the-log-files.aspx。
我在脚本中加入自动识别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)
---------------------------------------------------------脚本结束-----------------------------------------------------------------
我在脚本中加入自动识别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)
---------------------------------------------------------脚本结束-----------------------------------------------------------------
相关文章推荐
- 小心服务器内存居高不下的元凶--WebAPI服务
- 运维入门
- 利用开源软件打造自己的全功能远程工具
- Linux5.9无人值守安装
- 数据中心和云未来的十二大趋势
- 用vsftp快速搭建ftp服务器
- Linux快速构建apache web服务器
- 服务器监控策略浅谈
- 如何降低服务器采购成本 原理分析
- 建议的服务器分区办法
- 服务器托管六大优势分析
- Erlang实现的一个Web服务器代码实例
- 服务器技术全面解析
- 保护DNS服务器的几点方法小结
- 我国成为全球第二大服务器消费国
- 服务器 安全检查要点[星外提供]
- 服务器应用自动重新启动IIS批处理[原创]_DOS/BAT_脚本之家
- FTP 服务器关于权限的问题
- 批处理设置windows服务器的代码ThecSafe1.9.4第1/3页