zoukankan      html  css  js  c++  java
  • 清除 Exchange 2013/2016/2019 日志和ETL文件

    Exchange Server  的2个日志目录会增长的很快,需要定时清理,不然C盘的空间很快就会吃光,以下这个powershell脚本就是用于清理目录下面的日志的,已在生产环境中测试过,没问题:

    Set-Executionpolicy RemoteSigned
    $days=0
    $IISLogPath="C:inetpublogsLogFiles"
    $ExchangeLoggingPath="C:Program FilesMicrosoftExchange ServerV15Logging"
    $ETLLoggingPath="C:Program FilesMicrosoftExchange ServerV15BinSearchCeresDiagnosticsETLTraces"
    $ETLLoggingPath2="C:Program FilesMicrosoftExchange ServerV15BinSearchCeresDiagnosticsLogs"
    Function CleanLogfiles($TargetFolder)
    {
        if (Test-Path $TargetFolder) {
            $Now = Get-Date
            $LastWrite = $Now.AddDays(-$days)
            $Files = Get-ChildItem $TargetFolder -Include *.log,*.blg, *.etl, *.txt -Recurse | 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)

    以下这个powershell是修改版本,当用户没有对应的目录日志文件删除权限时也可以清理掉日志文件,如下:

    Set-Executionpolicy RemoteSigned
    $days=0
    $IISLogPath="C:inetpublogsLogFiles"
    $ExchangeLoggingPath="C:Program FilesMicrosoftExchange ServerV15Logging"
    $ETLLoggingPath="C:Program FilesMicrosoftExchange ServerV15BinSearchCeresDiagnosticsETLTraces"
    $ETLLoggingPath2="C:Program FilesMicrosoftExchange ServerV15BinSearchCeresDiagnosticsLogs"
    Function CleanLogfiles($TargetFolder)
    {
      write-host -debug -ForegroundColor Yellow -BackgroundColor Cyan $TargetFolder
    
        if (Test-Path $TargetFolder) {
            $Now = Get-Date
            $LastWrite = $Now.AddDays(-$days)
        #   $Files = Get-ChildItem $TargetFolder -Include *.log,*.blg, *.etl -Recurse | Where {$_.LastWriteTime -le "$LastWrite"}
            $Files = Get-ChildItem "C:Program FilesMicrosoftExchange ServerV15Logging"  -Recurse | Where-Object {$_.Name -like "*.log" -or $_.Name -like "*.blg" -or $_.Name -like "*.etl"}  | where {$_.lastWriteTime -le "$lastwrite"} | Select-Object FullName  
            foreach ($File in $Files)
                {
                   $FullFileName = $File.FullName  
                   Write-Host "Deleting file $FullFileName" -ForegroundColor "yellow"; 
                    Remove-Item $FullFileName -ErrorAction SilentlyContinue | out-null
                }
           }
    Else {
        Write-Host "The folder $TargetFolder doesn't exist! Check the folder path!" -ForegroundColor "red"
        }
    }
    CleanLogfiles($IISLogPath)
    CleanLogfiles($ExchangeLoggingPath)
    CleanLogfiles($ETLLoggingPath)
    CleanLogfiles($ETLLoggingPath2)

    具体可以参考链接:https://gallery.technet.microsoft.com/clear-exchange-2013-log-71abba44

  • 相关阅读:
    【bzoj1010-toy】斜率优化入门模板
    【bzoj1096-仓库建设】斜率优化
    【bzoj1911-[Apio2010]特别行动队】斜率优化
    【bzoj1597- [Usaco2008 Mar]土地购买】斜率优化
    【bzoj4310/hdu5030-跳蚤】后缀数组
    【bzoj2219-数论之神】求解x^a==b(%n)-crt推论-原根-指标-BSGS
    HDU6301 Distinct Values (多校第一场1004) (贪心)
    HDU6299 Balanced Sequence (多校第一场1002) (贪心)
    HDU6298 Maximum Multiple (多校第一场1001)
    NYOJ1238 最小换乘 (dijkstra)
  • 原文地址:https://www.cnblogs.com/reachos/p/9704959.html
Copyright © 2011-2022 走看看