Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added mailbox and archive free reporting #12

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Added mailbox and archive free reporting
  • Loading branch information
bwya77 committed Aug 27, 2022
commit b4a38b4a4f51de77ef4775edae68f6ec3bab2e52
75 changes: 30 additions & 45 deletions Office365/MailboxSizeReport.ps1
Original file line number Diff line number Diff line change
@@ -1,52 +1,38 @@
<#
.SYNOPSIS
Create report of all mailbox and archive sizes

.DESCRIPTION
Collects all the mailbox and archive stats from Exchange Online users. By default it will also
include the Shared Mailboxes.

.EXAMPLE
Get-MailboxSizeReport.ps1 -adminUPN [email protected]

Generate the mailbox size report with Shared mailboxes, mailbox archive and store
the csv file in the script root location.

Get-MailboxSizeReport.ps1
Generate the mailbox size report with Shared mailboxes, mailbox archive.
.EXAMPLE
Get-MailboxSizeReport.ps1 -adminUPN [email protected] -sharedMailboxes only

Get-MailboxSizeReport.ps1 -sharedMailboxes only
Get only the shared mailboxes

.EXAMPLE
Get-MailboxSizeReport.ps1 -adminUPN [email protected] -sharedMailboxes no

Get-MailboxSizeReport.ps1 -sharedMailboxes no
Get only the user mailboxes

.EXAMPLE
Get-MailboxSizeReport.ps1 -adminUPN [email protected] -archive:$false

Get-MailboxSizeReport.ps1 -archive:$false
Get the mailbox size without the archive mailboxes

.EXAMPLE
Get-MailboxSizeReport.ps1 -adminUPN [email protected] -path c:\temp\report.csv

Get-MailboxSizeReport.ps1 -CSVpath c:\temp\report.csv
Store CSV report in c:\temp\report.csv

.EXAMPLE
Get-MailboxSizeReport.ps1 | Format-Table
Print results for mailboxes in the console and format as table
.NOTES
Version: 1.2
Version: 1.3
Author: R. Mens - LazyAdmin.nl
Modified By: Bradley Wyatt - The Lazy Administrator
Creation Date: 23 sep 2021
Modified Date: 26 aug 2022
Purpose/Change: Check if we have a mailbox, before running the numbers
Link: https://lazyadmin.nl/powershell/office-365-mailbox-size-report
#>

param(
[Parameter(
Mandatory = $true,
HelpMessage = "Enter the Exchange Online or Global admin username"
)]
[string]$adminUPN,

[Parameter(
Mandatory = $false,
HelpMessage = "Get (only) Shared Mailboxes or not. Default include them"
Expand All @@ -64,7 +50,7 @@ param(
Mandatory = $false,
HelpMessage = "Enter path to save the CSV file"
)]
[string]$path = ".\MailboxSizeReport-$((Get-Date -format "MMM-dd-yyyy").ToString()).csv"
[string]$CSVpath
)

Function ConnectTo-EXO {
Expand Down Expand Up @@ -189,12 +175,14 @@ Function Get-MailboxStats {
"Deleted Items Size (GB)" = ConvertTo-Gb -size $mailboxSize.TotalDeletedItemSize.ToString().Split("(")[0]
"Item Count" = $mailboxSize.ItemCount
"Deleted Items Count" = $mailboxSize.DeletedItemCount
"Mailbox Warning Quota (GB)" = $_.IssueWarningQuota.ToString().Split("(")[0]
"Max Mailbox Size (GB)" = $_.ProhibitSendReceiveQuota.ToString().Split("(")[0]
"Mailbox Warning Quota (GB)" = ($_.IssueWarningQuota.ToString().Split("(")[0]).Split(" GB") | Select-Object -First 1
"Max Mailbox Size (GB)" = ($_.ProhibitSendReceiveQuota.ToString().Split("(")[0]).Split(" GB") | Select-Object -First 1
"Mailbox Free Space (GB)" = (($_.ProhibitSendReceiveQuota.ToString().Split("(")[0]).Split(" GB") | Select-Object -First 1) - (ConvertTo-Gb -size $mailboxSize.TotalItemSize.ToString().Split("(")[0])
"Archive Size (GB)" = $archiveSize
"Archive Items Count" = $archiveResult.ItemCount
"Archive Mailbox Free Space (GB)*" = (ConvertTo-Gb -size $_.ArchiveQuota.ToString().Split("(")[0]) - $archiveSize
"Archive Deleted Items Count" = $archiveResult.DeletedItemCount
"Archive Warning Quota (GB)" = $_.ArchiveWarningQuota.ToString().Split("(")[0]
"Archive Warning Quota (GB)" = ($_.ArchiveWarningQuota.ToString().Split("(")[0]).Split(" GB") | Select-Object -First 1
"Archive Quota (GB)" = ConvertTo-Gb -size $_.ArchiveQuota.ToString().Split("(")[0]
}

Expand All @@ -209,19 +197,16 @@ Function Get-MailboxStats {
# Connect to Exchange Online
ConnectTo-EXO

# Get mailbox status
Get-MailboxStats | Export-CSV -Path $path -NoTypeInformation -Encoding UTF8

if ((Get-Item $path).Length -gt 0) {
Write-Host "Report finished and saved in $path" -ForegroundColor Green
}else{
Write-Host "Failed to create report" -ForegroundColor Red
}


# Close Exchange Online Connection
$close = Read-Host Close Exchange Online connection? [Y] Yes [N] No

if ($close -match "[yY]") {
Disconnect-ExchangeOnline -Confirm:$false | Out-Null
If ($CSVpath) {
# Get mailbox status
Get-MailboxStats | Export-CSV -Path $CSVpath -NoTypeInformation -Encoding UTF8
if ((Get-Item $CSVpath).Length -gt 0) {
Write-Host "Report finished and saved in $CSVpath" -ForegroundColor Green
}
else {
Write-Host "Failed to create report" -ForegroundColor Red
}
}
Else {
Get-MailboxStats
}