-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGet-MailboxesItemAndSizeCSV.ps1
More file actions
50 lines (40 loc) · 1.52 KB
/
Get-MailboxesItemAndSizeCSV.ps1
File metadata and controls
50 lines (40 loc) · 1.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# Get-MailboxesItemAndSizeCSV
# A really rough implementation BETA
#
# Outputs A CSV in the current directory: mailbox_item_and_size.csv
#
# Author: David Midlo (david@avartec.com)
# Version: 0.0.1
#
# Usage:
# - use powershell's dot sourcing to import the function into your powershell session
# . .\Get-MailboxesItemAndSizeCSV.ps1
#
# - Run the command
# Get-MailboxesItemAndSizeCSV
#
# That's it!
function Get-MailboxesItemAndSizeCSV {
Add-PSSnapin Microsoft.Exchange.Management.PowerShell.SnapIn
$mailboxes = Get-Mailbox -ResultSize Unlimited
$results = @()
foreach ($mailbox in $mailboxes) {
Write-Host "Processing mailbox: $($mailbox.PrimarySmtpAddress)"
# Fetch the folder statistics for the current mailbox
$folders = Get-MailboxFolderStatistics -Identity $mailbox.UserPrincipalName
$result = [PSCustomObject]@{
UPN = $mailbox.UserPrincipalName
ItemCount = 0
Size = [Microsoft.Exchange.Data.ByteQuantifiedSize]::FromBytes(0) # Initialize with 0 bytes
}
foreach ($folder in $folders) {
$result.ItemCount += $folder.ItemsInFolder
$result.Size = [Microsoft.Exchange.Data.ByteQuantifiedSize]::FromBytes(
$result.Size.ToBytes() + $folder.FolderSize.ToBytes()
)
}
$results += $result
}
# Output the results
$results | Sort-Object -Descending -Property ItemCount | Export-Csv -Path "mailbox_item_and_size.csv" -NoTypeInformation
}