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: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67:
# Get-MailboxQuota.ps1 # Script for showing mailbox size and quota # Exit the script if username is not found If ($args[0] -eq $null) { Write-Host "Error: No user specified" -ForegroundColor "Red" break } # Get the username from the command line argument $username = $args[0] # Get the mailbox, break if it's not found $mb = Get-Mailbox $username -ErrorAction Stop # Get the mailbox statistics $mbstats = Get-MailboxStatistics $username # If the mailbox is using the database quotas then read them, otherwise read them from the mailbox If ($mb.UseDatabaseQuotaDefaults -eq $true) { $quota = (Get-MailboxDatabase -Identity $mb.Database).ProhibitSendQuota.Value.ToMB() } else { $quota = $mb.ProhibitSendQuota.Value.ToMB() } # Get the mailbox size and convert it from bytes to megabytes $size = $mbstats.TotalItemSize.Value.ToMB() # Write the output Write-Host "Mailbox: " $mb.DisplayName Write-Host "Size (MB): " $size Write-Host "Quota (MB):" $quota Write-Host "Percent: " ($size/$quota*100) Write-Host