MVP - Most Valuable Professional

Just can't get enough of IT

This blog is about mostly anything in IT. But the primary focuses are Microsoft technologies like Exchange Server, Microsoft 365, Microsoft Teams, and Cloud Security.


This script adds a new scheduled task for an Exchange Server 2013 environment in a new task scheduler group "Exchange".

When providing a username and password the scheduled task will be configured to "Run whether user is logged on or not".

When username and password are provided the Register-ScheduledTask cmdlet verfies the logon credentials and will fails, if the credentials provided (username/password) are not valid.

Note: The cmdlet Register-ScheduledTask consumes the user password in clear text.


# Create a new scheduled task using a dedicated service account
.\New-ScheduledExchangeTask.ps1 -TaskName "My Task" -ScriptName TaskScript1.ps1 -ScriptPath D:\Automation -TaskUser DOMAIN\ServiceAccount -Password P@ssw0rd

# Create a simple scheduled task
.\New-ScheduledExchangeTask.ps1 -TaskName "My Task" -ScriptName TaskScript1.ps1 -ScriptPath D:\Automation 

Version History

  • 1.0, Initial community release


Additional Credits


Read More »
Last updated: 2016-11-28

Exchange Server 2013Description

This script removes/disables HealthMailboxes that show an inconsistent error when querying monitoring mailboxes using

Get-Mailbox -Monitoring

and receiving a warning like

"WARNING: The object DOMAINNAME/Microsoft Exchange System Objects/Monitoring Mailboxes/Health_Mailbox_GUID has been corrupted,


# Remove the HealthMailbox(es) having an empty database attribute

.\Fix-HealthMailboxes.ps1 -Remove   

Version History

  • 1.0, Initial community release
  • 1.1, Some PowerShell hygiene




Read More »
On February 26, 2015
0 Comment

When you maintain a number of servers which require to trigger the same scheduled task manually, you can simplify the process by triggering the scheduled task remotely.

In this example, I assume that the script is being executed on a dedicated management server (aka job server) within an Exchange Server 2013 environment. The scheduled task must exist on all servers having the same name.

Create a simple PowerShell script at a file location of your choice (i.e. D:\Scripts\Start-RemoteScheduledTasks.ps1)

$cimSession = New-CimSession -ComputerName SERVER1,SERVER2,SERVER3,SERVER4
Start-ScheduledTask TASKNAME -CimSession $cimSession
Remove-CimSession $cimSession

Now create a new shortcut on your server desktop with the following configuration:

Target: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -command "& D:\Scripts\Start-RemoteScheduledTasks.ps1"

If required, select "Run as Administrator" in Shortcut -> Advanced settings.



This post has been published originally on my legacy blog SF-Tools.

Read More »
Last updated: 2017-10-10

Picture of four audio cassettesDescription

This script removes the proxy address(es) for a selected protocol from mail-enabled public folders.

Any proxy address with a given protocol is removed from the proxy addresses list.

The script can fix the alias of mail-enabled public folders as well. The code used is based upon a blog post by Shay Levy.



# Check mail enabled public folders for proxy addresses having "MS:" as a protocol type.
# Do not remove and update addresses, but log found addresses to RemovedAddresses.txt

.\Clean-MailEnabledPublicFolders.ps1 -ProtocolToRemove "MS:*" 

# Check mail enabled public folders for proxy addresses having "MS:" as a protocol type.
# Remove and update addresses and log found addresses to RemovedAddresses.txt

.\Clean-MailEnabledPublicFolders.ps1 -ProtocolToRemove "MS:*" -UpdateAddresses


Version History

  • 1.0, Initial community release
  • 1.1, FixAlias added, cleanup logic changed
  • 1.2, Some minor PowerShell updates






Additional Note

This Powershell script has been optimized using the ISESteroids™ add-on. Learn more about ISESteroids™ here.



Read More »
Last updated: 2020-03-12 | NOTE: If you are still using v2.1 update to themost recent 


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 administrative UNC path for file deletions.

Optionally, you can use the Active Directory configuration partition to determine the Exchange install path dynamically, if supported in your Active Directory environment.

  • It is assumed that the Exchange setup path is IDENTICAL across all Exchange servers, when not using the UseDynamicExchangePaths parameter
  • The IIS log file location is read from the local IIS Metabase of the LOCAL server where the script is executed 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
  • Use IsEdge switch when running on an Exchange Server holding the EDGE role


# Delete Exchange and IIS log files older than 14 days 

.\Purge-LogFiles -DaysToKeep 14

# Delete Exchange and IIS log files older than 7 days with automatic discovery

.\Purge-LogFiles -DaysToKeep 7 -Auto

# Delete Exchange and IIS log files older than 7 days with automatic discovery and send email report

.\Purge-LogFiles -DaysToKeep 7 -Auto -SendMail -MailFrom -MailTo -MailServer

# Delete Exchange and IIS log files older than 14 days, but copy files to a central repository and compress the log files before final deletion

.\Purge-LogFiles -DaysToKeep 14 -RepositoryRootPath \\OTHERSERVER\OtherShare\LOGS -ArchiveMode CopyZipAndDelete

# Delete Exchange Server, IIS, and HTTPERR log files older than 7 days, and send an HTML email. Identify Exchange file paths using AD configuration objects.

.\Purge-LogFiles.ps1 -DaysToKeep 7 -SendMail -MailFrom -MailTo -MailServer -UseDynamicExchangePaths -IncludeHttpErr

Version History

  • 2.3 Option for HTTPERR added, Option for dynamic Exchange install paths added, Html formatting added, tested with Exchange Server 2019
  • 2.21 Issue #12 fixed
  • 2.2 Minor fixes, but no changes
  • 2.14 Issue #9 fixed | IsEdge parameter added
  • 2.13 Issue #7 fixed | SendMail switch query
  • 2.11 Issue #6 fixed | Missing Remove-Item cmdlet
  • 2.1 Logfile archiving and archive compressions added
  • 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 configuration options added
  • 1.1 Variable fix and optional code added
  • 1.0 Initial community release



  • 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.
  • Windows Server 2012 R2 or newer
  • ActiveDirectory PowerShell module
  • Exchange 2013+ Management Shell




Additional Credits

Brian Reid, C7 Solutions,




Read More »