de-DEen-GB
 
rss

Just can't get enough of IT

This blog is about mostly anything in IT. But the primary focuses are Microsoft Technologies like Exchange, Office 365, Azure and Cloud Security.
On December 11, 2014
1 Comment
2375 Views

Exchange Server 2013 Exchange Server 2016 Description

This script deletes all Exchange and IIS logs older than X days from all Exchange 2013 servers that are fetched using the Get-ExchangeServer cmdlet.

The Exchange log file location is read from the environment variable and used to build an adminstrative UNC path for file deletions.

  • It is assumed that the Exchange setup path is IDENTICAL across all Exchange servers.
  • The IIS log file location is read from the local IIS metabase of the LOCAL server and is used to build an administrative UNC path for IIS log file deletions.
  • It is assumed that the IIS log file location is identical across all Exchange servers.

Examples

# EXAMPLE 1
# Delete Exchange and IIS log files older than 14 days 
.\Purge-LogFiles -DaysToKeep 14

# EXAMPLE 3
# Delete Exchange and IIS log files older than 7 days with automatic discovery
.\Purge-LogFiles -DaysToKeep 7 -Auto

# EXAMPLE 3
# Delete Exchange and IIS log files older than 7 days with automatic discovery and send email report
.\Purge-LogFiles -DaysToKeep 7 -Auto -SendMail -MailFrom postmaster@sedna-inc.com -MailTo exchangeadmin@sedna-inc.com -MailServer mail.sedna-inc.com

Version History

  • 2.0 CopyFilesBeforeDelete implemented
  • 1.93 Minor chances to PowerShell hygiene
  • 1.92 .Count issue fixed to run on Windows Server 2012
  • 1.91 Write DaysToKeep to log
  • 1.9 Global functions updated (write to event log)
  • 1.8 Support for global logging and other functions added
  • 1.6 Count Error fixed 1.7 Email report functionality added
  • 1.5 Sorting of server names added and Write-Host output changed
  • 1.4 Handling of IIS default location fixed
  • 1.3 Check if running in elevated mode added
  • 1.2 Auto/Manual configration options added
  • 1.1 Variable fix and optional code added
  • 1.0 Initial community release

Requirements

This PowerShell script requires the GlobalFunctions module, described here.

When using PowerShell 5 or later you can simply use Install-Module GlobalFunctions to install the module to your system.

Links

Last updated: 2017-04-10

Additional Credits

Brian Reid, C7 Solutions, http://www.c7solutions.com/2013/04/removing-old-exchange-2013-log-files-html

Follow

 

Read More »