<p>##### # # Name: Remove-ExchangeLogFiles.ps1 # Author: Brian Reid, @BrianReidC7 (Twitter); http://www.c7solutions.com/ # Reference: http://www.c7solutions.com/2013/04/removing-old-exchange-2013-log-files-html # # This script will get all Exchange 2013 servers in the organization and then delete the logs (older than 30 days) across all the # servers for you from one machine. You run this second script from Exchange Management Shell (run as administrator) and need remote # file access to C$ (or whichever folder you set in the script) to all the servers Exchange 2013 servers. # #####</p><p>Set-Executionpolicy RemoteSigned</p><p>$Days = 30 ### You can change the number of days here ### $ExchangeInstallRoot = "C" $IISLogPath = "Inetpub\logs\LogFiles\" $ExchangeLoggingPath = "Program Files\Microsoft\Exchange Server\V15\Logging\"</p><p>Write-Host "Removing IIS and Exchange logs; keeping last" $Days "days"</p><p>Function CleanLogfiles($TargetFolder) { $TargetServerFolder = "\\$E15Server\$ExchangeInstallRoot$\$TargetFolder"</p><p>Write-Host $TargetServerFolder</p><p> if (Test-Path $TargetServerFolder) { $Now = Get-Date $LastWrite = $Now.AddDays(-$Days) $Files = Get-ChildItem $TargetServerFolder -Include *.log -Recurse | Where {$_.LastWriteTime -le "$LastWrite"}</p><p> foreach ($File in $Files) { #Write-Host "Deleting file $File" -ForegroundColor "Red" ### Remove comment mark (#) from the front of this line to see files being deleted during script run ### Remove-Item $File -ErrorAction SilentlyContinue | out-null} }</p><p> else { Write-Host "The folder $TargetServerFolder doesn't exist! Check the folder path!" -ForegroundColor "red" } }</p><p>$EX2013 = Get-ExchangeServer | Where {$_.IsE15OrLater -eq $true} foreach ($E15Server In $EX2013) { CleanLogfiles($IISLogPath) CleanLogfiles($ExchangeLoggingPath) }</p>
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages1 Page
-
File Size-