Last active
May 27, 2016 13:20
-
-
Save ciphertxt/991c220d136b776fe97ee5fa3235244e to your computer and use it in GitHub Desktop.
Retrieves CSV with mailbox consumption and quotas for Office 365/Exchange Online
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$cred = Get-Credential | |
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $cred -Authentication Basic -AllowRedirection | |
Import-PSSession $Session | |
$mailboxes = Get-Mailbox -ResultSize Unlimited | |
foreach ($mailbox in $mailboxes) { | |
$mbSize = 0 | |
$mbSizeText = (Get-MailboxStatistics -Identity $mailbox.UserPrincipalName).TotalItemSize | |
if ($mbSizeText -ne "Unlimited") { | |
$mbSize = ((Get-MailboxStatistics -Identity $mailbox.UserPrincipalName).TotalItemSize -replace “(.*\()|,| [a-z]*\)”, “”) | |
} else { | |
$mbSize = -1 | |
} | |
$warningQuotaSize = 0 | |
$warningQuotaSizeText = $mailbox.IssueWarningQuota | |
if ($warningQuotaSizeText -ne "Unlimited") { | |
$warningQuotaSize = ($mailbox.IssueWarningQuota -replace “(.*\()|,| [a-z]*\)”, “”) | |
} else { | |
$warningQuotaSize = -1 | |
} | |
$prohibitSendQuota = 0 | |
$prohibitSendQuotaText = $mailbox.ProhibitSendQuota | |
if ($prohibitSendQuotaText -ne "Unlimited") { | |
$prohibitSendQuota = ($mailbox.ProhibitSendQuota -replace “(.*\()|,| [a-z]*\)”, “”) | |
} else { | |
$prohibitSendQuota = -1 | |
} | |
$output = New-Object -TypeName PSObject | |
$output | Add-Member -MemberType NoteProperty -Name UserPrincipalName -Value $mailbox.UserPrincipalName | |
$output | Add-Member -MemberType NoteProperty -Name DisplayName -Value $mailbox.DisplayName | |
$output | Add-Member -MemberType NoteProperty -Name IssueWarningQuotaGB -Value ([math]::Round($warningQuotaSize/1GB,2)) | |
$output | Add-Member -MemberType NoteProperty -Name ProhibitSendQuotaGB -Value ([math]::Round($prohibitSendQuota/1GB,2)) | |
$output | Add-Member -MemberType NoteProperty -Name TotalItemSizeMB -Value ([math]::Round($mbSize/1MB,2)) | |
$output | Add-Member -MemberType NoteProperty -Name TotalItemSizeGB -Value ([math]::Round($mbSize/1GB,2)) | |
$output | Add-Member -MemberType NoteProperty -Name ItemCount -Value (Get-MailboxStatistics -Identity $mailbox.UserPrincipalName).ItemCount | |
$output | Export-Csv -Append -NoTypeInformation .\Office365MailboxSizes.csv | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment