cancel
Showing results for 
Search instead for 
Did you mean: 
Rob_Wilcox1
Level 6
Partner

 

I was just wondering how to do this in Powershell : How to find out the number of items in each folder in a mailbox, and the sizes, and a summary for the whole mailbox.

I came up with this :

write-host "Arguments passed in : " $args

if ($args.length -eq 0)
{
	$mb = get-mailbox   -ResultSize unlimited
}
else
{
	write-host "Will run only against " $args[0]
	$mb = get-mailbox $args[0]
}

write-host "************************************************************"

foreach($m in $mb)
{
	if($m -eq $null)
	{
			continue
	}

	$totalsize = 0
	$totalitems = 0

	$stats = Get-MailboxFolderStatistics -Identity $m | `
		select FolderPath, ItemsInFolder, @{n="FolderSize";e={$_.FolderSize.ToKB()}}
	foreach($stat in $stats)
	{
		Write-Host "$($m.displayname) $($stat.FolderPath) $($stat.ItemsInFolder) $($stat.FolderSize)"
		$totalitems=$totalitems +$stat.ItemsInFolder
		$totalsize=$totalsize + $stat.foldersize

	}

	write-host "************************************************************"
	write-host "Total number of items " $totalitems
	write-host "Total Size for Mailbox (Kb) " $totalsize
	write-host "************************************************************"
}

The output looks like this :

Arguments passed in :  Mike Smith
Will run only against  Mike Smith
************************************************************
Mike Smith /Top of Information Store 1 0
Mike Smith /Calendar 9 23
Mike Smith /Contacts 1 0
Mike Smith /Conversation Action Settings 0 0
Mike Smith /Deleted Items 1 3
Mike Smith /Drafts 0 0
Mike Smith /Imported PST Files 1 0
Mike Smith /Imported PST Files/Bonny Walker PST 1 0
Mike Smith /Imported PST Files/Bonny Walker PST/Inbox 778 1362
Mike Smith /Imported PST Files/Bonny Walker PST/Inbox/User8 49 82
Mike Smith /Imported PST Files/Bonny Walker PST/Inbox/User9 89 150
Mike Smith /Imported PST Files/Bonny Walker PST/Inbox/UserA 70 117
Mike Smith /Imported PST Files/Bonny Walker PST/Inbox/UserB 81 136
Mike Smith /Imported PST Files/Bonny Walker PST/Inbox/UserC 84 142
Mike Smith /Imported PST Files/Bonny Walker PST/Inbox/UserD 84 141
Mike Smith /Imported PST Files/Craig Perez PST 1 0
Mike Smith /Imported PST Files/Craig Perez PST/Inbox 925 1613
Mike Smith /Imported PST Files/Craig Perez PST/Inbox/User1 87 145
Mike Smith /Imported PST Files/Craig Perez PST/Inbox/User2 88 146
Mike Smith /Imported PST Files/Craig Perez PST/Inbox/User4 81 135
Mike Smith /Inbox 331 977
Mike Smith /Inbox/Accounting, Tax, Finance 7 14
Mike Smith /Inbox/Active or Pending Litigation, Audit, Investigation Holds 8
Mike Smith /Inbox/Discussion Forum 56 177
Mike Smith /Inbox/General Corporate & Executive Level 7 14
Mike Smith /Inbox/HR & Personnel 7 13
Mike Smith /Inbox/Insurance 8 15
Mike Smith /Inbox/Marketing 2 8
Mike Smith /Journal 0 0
Mike Smith /Junk E-Mail 0 0
Mike Smith /Managed Folders 0 0
Mike Smith /Managed Folders/HR 1
Mike Smith /Managed Folders/Legal 3
Mike Smith /Managed Folders/Marketing 1
Mike Smith /News Feed 0 0
Mike Smith /Notes 0 0
Mike Smith /Old Files 2 3
Mike Smith /Other Languages 1 0
Mike Smith /Other Languages/Chinese 4 8
Mike Smith /Other Languages/Français 2 3
Mike Smith /Other Languages/Japanese 4 8
Mike Smith /Other Object Types 2 587
Mike Smith /Outbox 0 0
Mike Smith /Quick Step Settings 0 0
Mike Smith /Quick Step Settings 0 0
Mike Smith /RSS Feeds 0 0
Mike Smith /Sent Items 12 972
Mike Smith /Shortcut Examples 1 0
Mike Smith /Shortcut Examples/Full Body 4 7
Mike Smith /Shortcut Examples/No Body 3 3
Mike Smith /Shortcut Examples/With Banners 3 7
Mike Smith /Suggested Contacts 0 0
Mike Smith /Sync Issues 0 0
Mike Smith /Sync Issues/Conflicts 0 0
Mike Smith /Sync Issues/Local Failures 0 0
Mike Smith /Sync Issues/Server Failures 0 0
Mike Smith /Tasks 0 0
Mike Smith /Recoverable Items 0 0
Mike Smith /Deletions 0 0
Mike Smith /Purges 0 0
Mike Smith /Versions 0 0
************************************************************
Total number of items  2900
Total Size for Mailbox (Kb)  7026
************************************************************

Very nice !

Version history
Last update:
‎05-06-2011 05:34 AM
Updated by: