# Get-AllMailboxFolderStatistics.ps1
#
# Can be used to pull FolderID for all mailboxes (FolderID is often referenced in the audit logs).
#
# This can take a large time to run depending on number of mailboxes and number of folders (15 minutes is not uncommon)
#
# Outputs to a file called AllMailboxFolderStatistics.csv - this can grow into tens of MB, and in excess of 10000 rows, depending on tenant.
# If the file exists at the start, the script will abort.
$OutputFile="AllMailboxFolderStatistics.csv"
if(-Not (test-path -path $OutputFile))
{
$Mailboxes=Get-Mailbox
foreach ($Mailbox in $Mailboxes)
{
$stats=get-exomailboxfolderstatistics -userprincipalname $mailbox.userprincipalname
$stats | export-csv $OutputFile -notype -append
}
}
else
{
write-error "$OutputFile already exists - please remove this file before running."
}