News

Powershell script to test number of e-mails in an Exchange Public Folder

One of our clients has some automation on their Exchange box which 'autofiles' e-mails based on a reference number in the 'Subject' line. It is useful to know how many messages are in that particular branch of the PF tree.

#
# Script to count the number of msgs in the PubFol 'Recently added to Autofile'
# and email. Result is both an attachment and the body of the email.
# DKM 2023/04/12
#
Add-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010
$Output = Get-PublicFolderStatistics -Identity autofile"recently added to autofile"|Out-String
Send-MailMessage -To [email protected] -Subject 'AutofileStatus'  -Body $Output -SmtpServer 'anon-smtp.company.net' -From '[email protected]' -Attachments "C:\Temp\auto01.txt"

So this simple script loads the Exchange snap-in, gathers the statistics for the required PF and writes them to a file,then  inserts them into an e-mail and then mails it.

It is run on a weekly schedule via the Task Scheduler.

 

 

<< Go back to the previous page