PowerShell Script to return the total email or item count in office 365 online archive mailbox

Benard Mwanza 1,006 Reputation points
2021-10-02T21:31:38.603+00:00

I have created a simple custom PowerShell Script to export the total email or item count in office 365 archive mailboxes for all users who have online archiving enabled. However the script does not return the correct result. I called ItemCount with Get-mailboxstatistics
object.

In my office 365 I have one user account with online archiving enabled, the archive mailbox has three emails that I archived and then run start-managedfolderassistant cmdlet for that user.

The script still returns one item. What I'm I doing wrong. I'm expecting three itemcount.

Kindly assist.

Below is my script.

`$mails = get-mailbox -ResultSize Unlimited -archive
$mails | foreach-object{

$mailbox = $_.UserPrincipalName
$username = $_.DisplayName
$archive = get-mailboxstatistics -Identity $mailbox -archive

New-object -typename PSobject -property @{

UserPrincipalName = $mailbox
UserName = $username
TotalMessagesCount = $archive.ItemCount


}

} | Export-CSV "c:\results7.csv" -NoTypeInformation -Encoding UTF8`
Exchange Exchange Server Development
{count} votes

4 answers

Sort by: Most helpful
  1. Benard Mwanza 1,006 Reputation points
    2021-10-04T05:04:05.123+00:00

    Hi @KyleXu-MSFT

    Thank you for reply.

    Kindly note the script is to be run on office 365 accounts which have archive enabled. Can you kindly modify the script as you have mentioned for me to try out again.

    0 comments No comments

  2. Benard Mwanza 1,006 Reputation points
    2021-10-13T13:24:01.91+00:00

    Hi @KyleXu-MSFT

    Are you able to assist further on this, thank you.

    Kind regards,
    Bernard

    0 comments No comments

  3. Benard Mwanza 1,006 Reputation points
    2021-10-13T13:24:57.777+00:00

    Anyone following this question can help? I will appreciate. Thank you.

    0 comments No comments

  4. Richard van Nieuwenhuizen 1 Reputation point
    2022-08-23T08:57:07.51+00:00

    Something like this??

    $root = Get-MailboxFolderStatistics -Identity <user>

    $root | Select-Object FolderPath, VisibleItemsInFolder | Sort-Object -Property FolderPath

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.