{"id":196147,"date":"2023-08-28T15:53:49","date_gmt":"2023-08-28T20:53:49","guid":{"rendered":"https:\/\/itblog.ldlnet.net\/?p=196147"},"modified":"2024-05-10T08:35:34","modified_gmt":"2024-05-10T13:35:34","slug":"get-largemailboxinfo-ps1","status":"publish","type":"post","link":"https:\/\/itblog.ldlnet.net\/index.php\/2023\/08\/28\/get-largemailboxinfo-ps1\/","title":{"rendered":"Get-LargeMailboxInfo.ps1"},"content":{"rendered":"\n<p>Hello. I am going to be posting a few scripts that I have been working on to help run some reports. Hopefully, maybe these can get moved over to MS Graph as I get better at that module set. Anyway, this script will get all the User Mailboxes in the M365 tenant, check to see if it is 80 percent full and report on those mailboxes in a CSV file, no matter what EXO License plan they have. <\/p>\n\n\n\n<p>This is helpful if you&#8217;re making a case for Archive Mailboxes or you have multiple users complaining of their mailboxes getting full. Please review this script and provide any suggestions you may have for error handling or making the script better. I always welcome suggestions!<\/p>\n\n\n<pre class=\"lang:PowerShell nums:True\" title=\"Get-LargeMailboxInfo.ps1\">\n<#\n\n.SYNOPSIS\n\nGet a report of all mailboxes in your M365 tenant that are 80% full. \n \n\n.NOTES\n\n    Name: Get-HighUsageMailboxes.ps1\n\n    Author: Lance Lingerfelt \/ lance.lingerfelt@ldlnet.net\n\n    Version: 1.0\n\n    Modify Date: 2023-08-14\n\n#>\n\n#Define Report Path and Parameters\n\n[CmdletBinding()]\n\nParam(\n\n    [Parameter(Mandatory = $false)]\n\n    [string] $ReportsPath = \".\\Reports\",\n\n    [Parameter(Mandatory = $false)]\n\n    [float] $Threshold = 80\n      \n)\n\n# ================================================\n#               DO NOT MODIFY BEGIN\n# ================================================\n\n$ErrorActionPreference = 'SilentlyContinue'\n\n$Date = Get-Date -Format \"MM\/dd\/yyyy\"\n\n# Set Logging Configuration\n$Log = [PSCustomObject]@{\n    Path = \"C:\\Temp\\Logs\\Get-HighUsageMailboxes\"\n    Name = \"$($Date).log\"\n}\n\n# ================================================\n#                DO NOT MODIFY END\n# ================================================\n\n# ================================================\n#                   SCRIPT BEGIN\n# ================================================\n\n# Create New Logger Instance if Enabled\nif ($PSCmdlet.ShouldProcess(\"Create New Logger Instance\", $Log.Path)) {\n    # Import Logger Module\n    try {\n        if ( -not (Get-Module -Name PoShLog -ListAvailable) ) {\n            Install-Module -Name PoShLog -Scope CurrentUser -Force\n        }\n        else {\n            Import-Module -Name PoShLog -Force\n        }\n    }\n    catch {\n        Write-Host -Object \"Unable to import logger module. Error: $($_.Exception.Message)\"\n        exit 1\n    }\n\n    # Create New Logger Instance. Verbose logging level. Log to file and console. Start Logger.\n    New-Logger | `\n        Set-MinimumLevel -Value Verbose | `\n        Add-SinkFile -Path \"$($Log.Path)\\$($Log.Name)\" -OutputTemplate `\n        '{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{Level:u3}] {Message:lj}{NewLine}{Exception}' -RollingInterval Day | `\n        Add-SinkConsole | `\n        Start-Logger\n\n    # Log Start of Script\n    Write-VerboseLog \"Start of Script.\"\n}\n\nif ($PSCmdlet.ShouldProcess(\"Create New Exchange Online Instance\", $Log.Path)) {\n    # Import ExchangeOnlineManagement Module\n    try {\n        if ( -not (Get-Module -Name ExchangeOnlineManagement -ListAvailable) ) {\n            Install-Module -Name ExchangeOnlineManagement -Scope CurrentUser -Force\n        }\n        else {\n            Import-Module -Name ExchangeOnlineManagement -Force\n        }\n    }\n    catch {\n        Write-Host -Object \"Unable to import ExchangeOnlineManagement module. Error: $($_.Exception.Message)\"\n        exit 1\n    }\n\n}\n\n\n# Connect to Exchange Online\nConnect-ExchangeOnline -ShowBanner:$false\n\n#Export Array\n$exportresults = @()\n\n# Get all user mailboxes and their usage statistics\n$Mailboxes = Get-Mailbox -ResultSize Unlimited  \n$MailboxCount = $Mailboxes.count\n\n$i = 0\n#Loop through each result and create custom Values\nforeach ($Mailbox in $Mailboxes) {\n\n    $i++\n    Write-Host \"Evaluating [$($Mailbox.DisplayName)] Mailbox, Number [$i] of [$MailboxCount]\"\n\n    $MailboxStats = $Mailbox.UserPrincipalName | Get-MailboxStatistics\n\n    [float]$MailboxTotalUsage = [math]::Round($($MailboxStats.TotalItemSize.Value.ToString().Split(\"(\")[1].Split(\" \")[0].Replace(\",\", \"\") \/ 1GB), 2)\n    [float]$MailboxQuota = $Mailbox.ProhibitSendReceiveQuota.ToString().Split(\" \")[0]\n    [float]$UsagePercentage = $MailboxTotalUsage \/ $MailboxQuota * 100\n\n    if ($UsagePercentage -gt $Threshold) {\n        Write-Host \"Found a large mailbox for user [$($Mailbox.DisplayName)] where usage percentage is [$UsagePercentage]\" -ForegroundColor Yellow\n        Write-VerboseLog \"Found a large mailbox for user [$($Mailbox.DisplayName)] where usage percentage is [$UsagePercentage]\"\n        #Create the custom Objects for the Array and add them\n        $exportresults += [PSCustomObject]@{\n            User             = $Mailbox.DisplayName\n            TotalMailboxSize = $MailboxTotalUsage\n            Quota            = $MailboxQuota\n            UsagePercentage  = $UsagePercentage\n        }\n    }\n}\n\n#Create Report Path if not there\n\nif (Test-Path $ReportsPath) {\n    #Do Nothing \n}\nelse {\n    New-Item -Type Directory -Path $ReportsPath\n}\n\n#Export the Results   \n\n$exportresults | Export-Csv $ReportsPath\\HighUsageMailboxes-$(Get-Date -Format yyyyMMddThhmmss).csv -notypeinformation\n\n# Disconnect from Exchange Online\nDisconnect-ExchangeOnline -Confirm:$false\n\n# ================================================\n#                   SCRIPT END\n# ================================================\n\nWrite-VerboseLog \"End of Script. Exiting!\"\n\n<\/pre>\n\n\n\n<p>The script will output a CSV file that will look like this:<br>(NOTE: Values are in GB per the script)<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"957\" height=\"883\" src=\"https:\/\/itblog.ldlnet.net\/wp-content\/uploads\/2023\/08\/image.png\" alt=\"\" class=\"wp-image-196153\"\/><\/figure>\n\n\n\n<p>Conclusion: If you need a report to show mailboxes nearing their quota without it being too close, then this script is for you. Thanks again!!!!<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">About Lance Lingerfelt<\/h2>\n\n\n\n<div class=\"wp-block-media-text is-stacked-on-mobile\" style=\"grid-template-columns:22% auto\"><figure class=\"wp-block-media-text__media\"><img loading=\"lazy\" decoding=\"async\" width=\"468\" height=\"412\" src=\"https:\/\/itblog.ldlnet.net\/wp-content\/uploads\/2024\/03\/ProfLDL1.jpg\" alt=\"Lance Lingerfelt Profile Photo\" class=\"wp-image-196223 size-full\"\/><\/figure><div class=\"wp-block-media-text__content\">\n<p class=\"has-small-font-size\">Lance Lingerfelt is an M365 Specialist and Evangelist with over 20 years of experience in the Information Technology field. Having worked in enterprise environments to small businesses, he is able to adapt and provide the best IT Training and Consultation possible. With a focus on AI, the M365 Stack, and Healthcare, he continues to give back to the community with training, public speaking events, and this blog.<\/p>\n<\/div><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Hello. I am going to be posting a few scripts that I have been working on to help run some reports. Hopefully,<\/p>\n<p class=\"link-more\"><a class=\"myButt \" href=\"https:\/\/itblog.ldlnet.net\/index.php\/2023\/08\/28\/get-largemailboxinfo-ps1\/\">Read More<\/a><\/p>\n","protected":false},"author":1,"featured_media":147,"comment_status":"closed","ping_status":"closed","sticky":true,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4,265,194,3,1],"tags":[9,303,309,8,13],"class_list":["post-196147","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-exchange","category-microsoft365","category-office365","category-powershell","category-uncategorized","tag-exchange","tag-exchange-online","tag-mailboxes","tag-powershell","tag-script","odd"],"_links":{"self":[{"href":"https:\/\/itblog.ldlnet.net\/index.php\/wp-json\/wp\/v2\/posts\/196147","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/itblog.ldlnet.net\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/itblog.ldlnet.net\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/itblog.ldlnet.net\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/itblog.ldlnet.net\/index.php\/wp-json\/wp\/v2\/comments?post=196147"}],"version-history":[{"count":17,"href":"https:\/\/itblog.ldlnet.net\/index.php\/wp-json\/wp\/v2\/posts\/196147\/revisions"}],"predecessor-version":[{"id":196304,"href":"https:\/\/itblog.ldlnet.net\/index.php\/wp-json\/wp\/v2\/posts\/196147\/revisions\/196304"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/itblog.ldlnet.net\/index.php\/wp-json\/wp\/v2\/media\/147"}],"wp:attachment":[{"href":"https:\/\/itblog.ldlnet.net\/index.php\/wp-json\/wp\/v2\/media?parent=196147"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/itblog.ldlnet.net\/index.php\/wp-json\/wp\/v2\/categories?post=196147"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/itblog.ldlnet.net\/index.php\/wp-json\/wp\/v2\/tags?post=196147"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}