Functions/Get-Mailboxsizes.ps1
function Get-MailboxSizes { param ( [Parameter(ValueFromPipeline, ValueFromPipelineByPropertyName = $true)] [string] $Identity ) $Output = @() if ($Identity) { $Mailboxen = Get-EXOMailbox -Identity $Identity $ArchiveMailboxen = Get-EXOMailbox -Identity $Identity -Archive } else { $Mailboxen = Get-EXOMailbox -ResultSize unlimited | Where-Object DisplayName -NE "Discovery Search Mailbox" $ArchiveMailboxen = Get-EXOMailbox -ResultSize unlimited -Archive } foreach ($mbx in $Mailboxen) { $i++ if (($Mailboxen).Count -gt 1) { Write-Progress -Activity "Getting Mailbox Statistics" -Status "Running... $i/$($Mailboxen.count)" -PercentComplete (($i / ($Mailboxen.Count)) * 100) } $Stats = Get-EXOMailboxStatistics -Identity $mbx.UserPrincipalName | Select-Object @{name = "TotalItemSize (MB)"; expression = { [math]::Round((($_.TotalItemSize.Value.ToString()).Split("(")[1].Split(" ")[0].Replace(",", "") / 1MB), 2) } }, ItemCount if ($ArchiveMailboxen.Guid -contains $mbx.Guid) { $ArchiveStats = Get-EXOMailboxStatistics -Identity $mbx.UserPrincipalName -Archive | Select-Object @{name = "TotalItemSize (MB)"; expression = { [math]::Round((($_.TotalItemSize.Value.ToString()).Split("(")[1].Split(" ")[0].Replace(",", "") / 1MB), 2) } }, ItemCount } else { Remove-Variable ArchiveStats -ea 0 } $obj = [PSCustomObject]@{ UserPrincipalName = $mbx.UserPrincipalName DisplayName = $mbx.DisplayName "TotalItemSize (MB)" = $Stats."TotalItemSize (MB)" ItemCount = $Stats.ItemCount "Archive Size (MB)" = $ArchiveStats."TotalItemSize (MB)" ArchiveItemCount = $ArchiveStats.ItemCount } # if ($ArchiveStats) { # $obj | Add-Member -MemberType NoteProperty -Name "Archive TotalItemSize (MB)" -Value $ArchiveStats."TotalItemSize (MB)" # $obj | Add-Member -MemberType NoteProperty -Name "ArchiveItemCount" -Value $ArchiveStats.ItemCount # } $Output += $obj } return $Output } |