Last active
May 7, 2020 12:11
-
-
Save robderickson/40312e991b027966deab2fa53233ef65 to your computer and use it in GitHub Desktop.
Get sum of items, deleted items, total item sizes, and deleted item sizes for all specified mailboxes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Get-MailboxItemTotal { | |
[CmdletBinding()] | |
param( | |
$Identity | |
) | |
PROCESS { | |
if ($Identity) { | |
Write-Verbose 'Getting specified mailboxes.' | |
$Identities = $Identity | Foreach-Object {Get-Mailbox -Identity $_} | Select-Object -ExpandProperty Identity | |
} else { | |
Write-Verbose 'Getting all mailboxes.' | |
$Identities = Get-Mailbox -ResultSize Unlimited | Select-Object -ExpandProperty Identity | |
} | |
Write-Verbose 'Getting statistics.' | |
$ItemStats = foreach ($id in $Identities) { | |
Get-MailboxStatistics $id | Select-Object -Property @( | |
'ItemCount' | |
@{ Name = 'TotalItemSize'; Expression = { $_.TotalItemSize.Value.ToBytes() } } | |
'DeletedItemCount' | |
@{ Name = 'TotalDeletedItemSize'; Expression = { $_.TotalDeletedItemSize.Value.ToBytes() } } | |
) | |
} | |
$Properties = @{ | |
TotalItemCount = ($ItemStats | Measure-Object -Property ItemCount -Sum).Sum | |
TotalItemSize = ($ItemStats | Measure-Object -Property TotalItemSize -Sum).Sum / 1TB | |
TotalDeletedItemCount = ($ItemStats | Measure-Object -Property DeletedItemCount -Sum).Sum | |
TotalDeletedItemSize = ($ItemStats | Measure-Object -Property TotalDeletedItemSize -Sum).Sum / 1TB | |
} | |
New-Object -TypeName PSCustomObject -Property $Properties | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment