question

49539302 avatar image
0 Votes"
49539302 asked KyleXu-MSFT commented

How to clear Exchange Logs without any impact for Exchange 2016 (CU19) C Drive Disk space increase fastly.

Hello Support

I got the script for clearing logs. These are fine

is it safe to delete below the path of logs? after the backup completed?

Set execution policy if not set

$ExecutionPolicy = Get-ExecutionPolicy
if ($ExecutionPolicy -ne "RemoteSigned") {
Set-ExecutionPolicy RemoteSigned -Force
}

Cleanup logs older than the set of days in numbers

$days = 2

Path of the logs that you like to cleanup

$IISLogPath = "C:\inetpub\logs\LogFiles\"
$ExchangeLoggingPath = "C:\Program Files\Microsoft\Exchange Server\V15\Logging\"
$ETLLoggingPath = "C:\Program Files\Microsoft\Exchange Server\V15\Bin\Search\Ceres\Diagnostics\ETLTraces\"
$ETLLoggingPath2 = "C:\Program Files\Microsoft\Exchange Server\V15\Bin\Search\Ceres\Diagnostics\Logs\"
$ExchangeLoggingPath = "C:\Program Files\Microsoft\Exchange Server\V15\TransportRoles\Logs\"

Clean the logs

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 -Recurse | Where-Object { $_.Name -like "*.log" -or $_.Name -like "*.blg" -or $_.Name -like "*.etl" } | Where-Object { $_.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)

But here i want mail notification like what are the files are deleted. those details to be sent by mail
Please advise how to add this Mail notification part? in the existing script

office-exchange-online-itpro
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

@49539302
I am writing here to confirm with you any update about this thread now?
If the suggestion below helps, please be free to mark it as an answer for helping more people.

0 Votes 0 ·
KyleXu-MSFT avatar image
0 Votes"
KyleXu-MSFT answered

@49539302

Our forum does not support scripting on demand so far. If you need a script to complete a job, you may need to open a ticket to Microsoft which supported for it.

About this existing script, you can modify those two places, then this script will generate and save a log:
86677-qa-kyle-11-29-18.png
86663-qa-kyle-11-29-48.png

If you want to send it with email, you will need to writing another script to do it.


If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

49539302 avatar image
0 Votes"
49539302 answered KyleXu-MSFT commented

Thank you KyleXu

is it safe to cleanup below paths of logs?

$IISLogPath = "C:\inetpub\logs\LogFiles\"
$ExchangeLoggingPath = "C:\Program Files\Microsoft\Exchange Server\V15\Logging\"
$ETLLoggingPath = "C:\Program Files\Microsoft\Exchange Server\V15\Bin\Search\Ceres\Diagnostics\ETLTraces\"
$ETLLoggingPath2 = "C:\Program Files\Microsoft\Exchange Server\V15\Bin\Search\Ceres\Diagnostics\Logs\"
$ExchangeLoggingPath = "C:\Program Files\Microsoft\Exchange Server\V15\TransportRoles\Logs\"

· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Yes, you can. Those log only used to record actions, if you doesn't need them, you could delete them from your Exchange server.

0 Votes 0 ·
AndyDavid avatar image
0 Votes"
AndyDavid answered

yes, absolutely.
The only logs you do not want to clear using a script are the Exchange database transaction logs.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.