User Profile
Minseok_Song
Iron Contributor
Joined 2 years ago
User Widgets
Recent Discussions
Re: Email IT department a report of a specific mailbox reaching 90% storage quota
AB21805 If you want to connect to Exchange Online using a managed identity in Azure Automation, you must specify the -UseManagedIdentity flag, which works without the additional Credential parameter. Original code Connect-ExchangeOnline Modified code Connect-ExchangeOnline -UseManagedIdentity -Verbose And if you're using Azure Automation, my understanding is that you need to use Azure Automation to get the credentials, and you can do that by modifying the code that sends the email like this. Original code # Send an email notification $emailBody = "The mailbox $($mailboxIdentity) has reached $($totalMailboxSize) GB, which exceeds 90% of the warning quota." Send-MailMessage -To "email address removed for privacy reasons" -From "email address removed for privacy reasons" -Subject "Mailbox Size Warning" -Body $emailBody -SmtpServer "smtp.office365.com" -Port 587 -UseSsl -Credential (Get-Credential) Modified code # Automation Account Credential $credential = Get-AutomationPSCredential -Name 'SMTPCredential' # Send an email notification $emailBody = "The mailbox $($mailboxIdentity) has reached $($totalMailboxSize) GB, which exceeds 90% of the warning quota." Send-MailMessage -To "email address removed for privacy reasons" -From "email address removed for privacy reasons" -Subject "Mailbox Size Warning" -Body $emailBody -SmtpServer "smtp.office365.com" -Port 587 -UseSsl -Credential $smtpCredential I've provided the code below for you to try out. Since I'm not currently able to test this code myself, it may require some adjustments, especially in the credential methods, to meet your specific needs. # Connect to Exchange Online using Managed Identity Connect-ExchangeOnline -UseManagedIdentity -Verbose # Specify the user's mailbox identity $mailboxIdentity = "email address removed for privacy reasons" # Get mailbox configuration and statistics for the specified mailbox $mailboxConfig = Get-Mailbox -Identity $mailboxIdentity $mailboxStats = Get-MailboxStatistics -Identity $mailboxIdentity # Check if TotalItemSize and ProhibitSendQuota are not null and extract the sizes if ($mailboxStats.TotalItemSize -and $mailboxConfig.ProhibitSendQuota) { $totalSizeBytes = $mailboxStats.TotalItemSize.Value.ToString().Split("(")[1].Split(" ")[0].Replace(",", "") -as [double] $prohibitQuotaBytes = $mailboxConfig.ProhibitSendQuota.ToString().Split("(")[1].Split(" ")[0].Replace(",", "") -as [double] # Convert sizes from bytes to gigabytes $totalMailboxSize = $totalSizeBytes / 1GB $mailboxWarningQuota = $prohibitQuotaBytes / 1GB # Check if the mailbox size exceeds 90% of the warning quota if ($totalMailboxSize -ge ($mailboxWarningQuota * 0.9)) { # Retrieve SMTP credentials from Azure Automation Credential $smtpCredential = Get-AutomationPSCredential -Name 'SMTPCredential' # Send an email notification $emailBody = "The mailbox $($mailboxIdentity) has reached $($totalMailboxSize) GB, which exceeds 90% of the warning quota." Send-MailMessage -To "email address removed for privacy reasons" -From "email address removed for privacy reasons" -Subject "Mailbox Size Warning" -Body $emailBody -SmtpServer "smtp.office365.com" -Port 587 -UseSsl -Credential $smtpCredential } } else { Write-Host "The required values(TotalItemSize or ProhibitSendQuota) are not available." }1.3KViews0likes2CommentsRe: Email IT department a report of a specific mailbox reaching 90% storage quota
AB21805I'll outline the code changes below and detail the specific problems I encountered and solved. 1. Type Error Firstly, there was a type error in the original code, which I have corrected as follows: Original code $mailboxStats.TotalItemSize $mailboxStats.ProhibitSendQuota Modified code $totalSizeBytes = $mailboxStats.TotalItemSize.Value.ToString().Split("(")[1].Split(" ")[0].Replace(",", "") -as [double] $prohibitQuotaBytes = $mailboxConfig.ProhibitSendQuota.ToString().Split("(")[1].Split(" ")[0].Replace(",", "") -as [double] 2. method error There was a problem where ProhibitSendQuota was called on the wrong object, which I have fixed in the modified code below. This may have been one of the reasons why the code did not work correctly the first time you ran it. Original code $mailboxStats = Get-MailboxStatistics -Identity $mailboxIdentity $mailboxStats.TotalItemSize $mailboxStats.ProhibitSendQuota Modified code $mailboxConfig = Get-Mailbox -Identity $mailboxIdentity $mailboxStats = Get-MailboxStatistics -Identity $mailboxIdentity $mailboxStats.TotalItemSize $mailboxConfig.ProhibitSendQuota 3. Credential error I encountered an authentication-related error when sending mail, so I made some adjustments to the port number and updated the code accordingly. Original code Send-MailMessage -To "email address removed for privacy reasons" -From "email address removed for privacy reasons" -Subject "Mailbox Size Warning" -Body $emailBody -SmtpServer "Smtp.office365.com" Modified code Send-MailMessage -To "email address removed for privacy reasons" -From "email address removed for privacy reasons" -Subject "Mailbox Size Warning" -Body $emailBody -SmtpServer "smtp.office365.com" -Port 587 -UseSsl -Credential (Get-Credential) Finally, I made some changes to the logic. While testing the code, I noticed errors when variables like ProhibitSendQuota came in as null, so I adjusted the code to handle such cases more gracefully.1.4KViews1like4CommentsRe: Email IT department a report of a specific mailbox reaching 90% storage quota
Hi AB21805, I tested it on EXO V3 and here is the revised code. I found some other errors besides the existing type error, so I fixed the code in general. I'll give you the full modified code first and explain it. The modified code works fine in my local environment. # Connect to Exchange Online Connect-ExchangeOnline # Specify the user's mailbox identity $mailboxIdentity = "email address removed for privacy reasons" # Get mailbox configuration and statistics for the specified mailbox $mailboxConfig = Get-Mailbox -Identity $mailboxIdentity $mailboxStats = Get-MailboxStatistics -Identity $mailboxIdentity # Check if TotalItemSize and ProhibitSendQuota are not null and extract the sizes if ($mailboxStats.TotalItemSize -and $mailboxConfig.ProhibitSendQuota) { $totalSizeBytes = $mailboxStats.TotalItemSize.Value.ToString().Split("(")[1].Split(" ")[0].Replace(",", "") -as [double] $prohibitQuotaBytes = $mailboxConfig.ProhibitSendQuota.ToString().Split("(")[1].Split(" ")[0].Replace(",", "") -as [double] # Convert sizes from bytes to gigabytes $totalMailboxSize = $totalSizeBytes / 1GB $mailboxWarningQuota = $prohibitQuotaBytes / 1GB # Check if the mailbox size exceeds 90% of the warning quota if ($totalMailboxSize -ge ($mailboxWarningQuota * 0.9)) { # Send an email notification $emailBody = "The mailbox $($mailboxIdentity) has reached $($totalMailboxSize) GB, which exceeds 90% of the warning quota." Send-MailMessage -To "email address removed for privacy reasons" -From "email address removed for privacy reasons" -Subject "Mailbox Size Warning" -Body $emailBody -SmtpServer "smtp.office365.com" -Port 587 -UseSsl -Credential (Get-Credential) } } else { Write-Host "The required values(TotalItemSize or ProhibitSendQuota) are not available." } To test if the mail sending function was working, I temporarily modified the condition to if ($totalMailboxSize -ge ($mailboxWarningQuota * 0.0)).1.4KViews0likes5CommentsRe: Email IT department a report of a specific mailbox reaching 90% storage quota
Hi AB21805 , I don't think you need to lower the version because of this issue. Let me test the code again in my EXO V3 environment and get back to you with a cleaned up answer. I looked it up and it seems to work fine if you convert the TotalItemSize to a string and then double it.1.4KViews0likes7CommentsRe: Email IT department a report of a specific mailbox reaching 90% storage quota
I'm using a different version of PowerShell, so I can't give you the exact code for your version. To change the data types of TotalItemSize and ProhibitSendQuota, you will need to refer to the documentation for the objects that contain these properties or related materials. If you need help, you can refer to the official documentation for your version of PowerShell or ask someone else for help again. Thank you.1.5KViews0likes9CommentsRe: Email IT department a report of a specific mailbox reaching 90% storage quota
AB21805 I took a look at the latest documentation and made some changes to the code to match the v3 exo version. In the end, the main cause of the problem was that the TotalItemSize and the ProhibitSendQuota type were not returned in byte form. If you encounter this error in the future, please be aware of it and change the code accordingly. Thank you very much. # Connect to Exchange Online Connect-ExchangeOnline # Specify the user's mailbox identity $mailboxIdentity = "email address removed for privacy reasons" # Get mailbox statistics for the specified mailbox $mailboxStats = Get-EXOMailboxStatistics -Identity $mailboxIdentity # Check if mailbox size exceeds the warning quota if ($mailboxStats.TotalItemSize.ToBytes() -gt 0 -and $mailboxStats.ProhibitSendQuota.ToBytes() -gt 0) { $totalMailboxSize = $mailboxStats.TotalItemSize.ToBytes() / 1GB $mailboxWarningQuota = $mailboxStats.ProhibitSendQuota.ToBytes() / 1GB if ($totalMailboxSize -ge ($mailboxWarningQuota * 0.9)) { # Send an email notification $emailBody = "The mailbox $($mailboxIdentity) has reached $($totalMailboxSize) GB, which exceeds 90% of the warning quota." Send-MailMessage -To "email address removed for privacy reasons" -From "email address removed for privacy reasons" -Subject "Mailbox Size Warning" -Body $emailBody -SmtpServer "Smtp.office365.com" } } Code changes Get-MailboxStatistics -> Get-EXOMailboxStatistics TotalItemSize.Value.ToBytes() -> TotalItemSize.ToBytes() ProhibitSendQuota.Value.ToBytes() -> ProhibitSendQuota.ToBytes()1.5KViews0likes11CommentsRe: Email IT department a report of a specific mailbox reaching 90% storage quota
AB21805 I've checked my proposed code and found some places where it might cause additional type issues, I'll re-propose the code below with those fixes, thanks. # Connect to Exchange Online Connect-ExchangeOnline # Specify the user's mailbox identity $mailboxIdentity = "email address removed for privacy reasons" # Get mailbox statistics for the specified mailbox $mailboxStats = Get-MailboxStatistics -Identity $mailboxIdentity # Check if mailbox size exceeds the warning quota if ($mailboxStats.TotalItemSize.Value.ToBytes() -gt 0 -and $mailboxStats.ProhibitSendQuota.Value.ToBytes() -gt 0) { $totalMailboxSize = $mailboxStats.TotalItemSize.Value.ToBytes() / 1GB $mailboxWarningQuota = $mailboxStats.ProhibitSendQuota.Value.ToBytes() / 1GB if ($totalMailboxSize -ge ($mailboxWarningQuota * 0.9)) { # Send an email notification $emailBody = "The mailbox $($mailboxIdentity) has reached $($totalMailboxSize) GB, which exceeds 90% of the warning quota." Send-MailMessage -To "email address removed for privacy reasons" -From "email address removed for privacy reasons" -Subject "Mailbox Size Warning" -Body $emailBody -SmtpServer "Smtp.office365.com" } }1.6KViews1like13CommentsRe: Email IT department a report of a specific mailbox reaching 90% storage quota
Below is the modified code # Connect to Exchange Online Connect-ExchangeOnline # Specify the user's mailbox identity $mailboxIdentity = "email address removed for privacy reasons" # Get mailbox statistics for the specified mailbox $mailboxStats = Get-MailboxStatistics -Identity $mailboxIdentity # Check if mailbox size exceeds the warning quota if ($mailboxStats.TotalItemSize -gt 0 -and $mailboxStats.ProhibitSendQuota -gt 0) { $totalMailboxSize = $mailboxStats.TotalItemSize.Value.ToBytes() / 1GB $mailboxWarningQuota = $mailboxStats.ProhibitSendQuota.Value.ToBytes() / 1GB if ($totalMailboxSize -ge ($mailboxWarningQuota * 0.9)) { # Send an email notification $emailBody = "The mailbox $($mailboxIdentity) has reached $($totalMailboxSize) GB, which exceeds 90% of the warning quota." Send-MailMessage -To "email address removed for privacy reasons" -From "email address removed for privacy reasons" -Subject "Mailbox Size Warning" -Body $emailBody -SmtpServer "Smtp.office365.com" } } Before modification $totalMailboxSize = $mailboxStats.TotalItemSize / 1GB $mailboxWarningQuota = $mailboxStats.ProhibitSendQuota / 1GB After modification $totalMailboxSize = $mailboxStats.TotalItemSize.Value.ToBytes() / 1GB $mailboxWarningQuota = $mailboxStats.ProhibitSendQuota.Value.ToBytes() / 1GB Thank you Best regards, Minseok Song1.6KViews0likes15CommentsRe: Email IT department a report of a specific mailbox reaching 90% storage quota
Hi AB21805 , I've reviewed the code you provided and noticed a problem with the data types used. I understand that the values returned for TotalItemSize and ProhibitSendQuota are not simple numbers, but complex objects that contain data capacity (ByteQuantifiedSize type). This would make direct comparisons between them problematic. I'd like to propose a modification to the script that solves this problem by properly converting these values into a comparable format. I'll post the revised code in the comments below.1.6KViews0likes16Comments
Recent Blog Articles
Stop Translating Docs Manually! Automate Your Global Reach with Co-op Translator v0.8 Series
Stop Translating Docs Manually! Automate Your Global Reach with Co-op Translator v0.8 Series Is your team or open-source project drowning in the endless cycle of manually translating documentat...271Views0likes0CommentsAutomate Markdown and Image Translations Using Co-op Translator: Phi-3 Cookbook Case Study
Co-op Translator is an open source tool designed to automate the translation of Markdown files and images containing embedded text into multiple languages. Powered by Azure AI Services, it streamline...2.2KViews2likes1CommentEvaluate Fine-tuned Phi-3 / 3.5 Models in Azure AI Studio Focusing on Microsoft's Responsible AI
Fine-tuning a model can sometimes lead to unintended or undesired responses. To ensure that the model remains safe and effective, it's important to evaluate the model's potential to generate harmful ...19KViews1like1CommentFine-Tune and Integrate Custom Phi-3 Models with Prompt Flow in Azure AI Studio
Phi-3 is a family of small language models (SLMs) developed by Microsoft that delivers exceptional performance and cost-effectiveness. In this tutorial, you will learn how to fine-tune the Phi-3 mo...20KViews1like0CommentsFine-Tune and Integrate Custom Phi-3 Models with Prompt Flow: Step-by-Step Guide
In this tutorial, you will learn how to fine-tune the Phi-3 model and integrate it with Prompt Flow. By leveraging Azure Machine Learning, and Prompt flow you will establish a workflow for deployin...32KViews2likes1CommentBuild a chatbot service to ensure safe conversations: Using Azure Content Safety & Azure OpenAI
This tutorial is ideal for anyone who wants to build a chatbot service with strong content moderation capabilities. In this tutorial, you will learn how to build a chatbot service that interacts wi...7.6KViews1like2CommentsTeach ChatGPT to Answer Questions: Using Azure AI Search & Azure OpenAI (Lang Chain)
In this two-part series, we will explore how to build intelligent service using Azure. In Series 1, we'll use Azure AI Search to extract keywords from unstructured data stored in Azure Blob Storage...43KViews4likes9Comments