In diesem Artikel besprechen wir das PowerShell-Skript, das ich vorbereitet habe, um die Postfachkontingente von Benutzern in einer bestimmten Datenbank zu überprüfen und Benachrichtigungen für Konten zu senden, die den angegebenen Schwellenwert überschreiten.
Darüber hinaus verwendet das Skript eine XML-Datei, um SMTP-Anmeldeinformationen sicher zu speichern und zu verwenden.

Exchange Server In kritischen Umgebungen sind Postfachkontingente wichtig für die effiziente Nutzung von Systemressourcen. Wenn Benutzer bestimmte Kontingentgrenzen überschreiten, müssen sich Systemadministratoren dieser Situation bewusst sein.
Details zum Exchange Server-Postfachkontingent-Benachrichtigungsskript
Das Skript prüft die Kontingentnutzung aller Benutzerpostfächer in der angegebenen Exchange-Datenbank. Wenn das Benutzerkontingent über dem angegebenen Schwellenwert liegt, wird eine Warn-E-Mail mit den relevanten Kontoinformationen gesendet.
Konfigurieren des Exchange Server-Postfachkontingent-Benachrichtigungsskripts
- Ermittlung von Datenbank und Schwellenwert:
$Database = "DB01"
: Datenbank zur Überprüfung austauschen.$Threshold = "5"
: Schwellenwert für die Kontingentnutzung, bestimmt als Prozentsatz.
- SMTP-Servereinstellungen:
$From = "[email protected]"
: E-Mail-Adresse des Absenders.$Server = "mail.cengizyilmaz.net"
: Der zu verwendende Mailserver.$Port = 587
: Portnummer des Mailservers.$To = "[email protected]"
: Die Adresse, an die die Benachrichtigungs-E-Mail gesendet wird.$Subject = "Journal Mailbox Kota Uyarısı!"
: E-Mail-Betreff.
- SMTP-Anmeldeinformationsverwaltung:
- SMTP-Anmeldeinformationen werden vom Benutzer eingeholt und sicher gespeichert.
$CredObj
wird in der Datei gespeichert. - Identitätsinformationen werden im XML-Format für die zukünftige Verwendung gespeichert und bei Bedarf hochgeladen.
- SMTP-Anmeldeinformationen werden vom Benutzer eingeholt und sicher gespeichert.
- Kontingentstatusprüfung und E-Mail-Versand:
- Das Skript ruft Postfachstatistiken aller Benutzer in der Datenbank ab.
- Für Benutzer, deren Kontingentnutzung den angegebenen Schwellenwert überschreitet, wird ein Bericht im HTML-Format generiert und per E-Mail versendet.
- Protokollierung und Fehler:
- Bei allen Vorgängen sind Fehler aufgetreten
$DirPathLog.txt
wird in der Datei gespeichert.
- Bei allen Vorgängen sind Fehler aufgetreten
<#
#################################################################################################################
# Yayınlanma Tarihi: 17.02.2023
# Cengiz YILMAZ
# MCT
# https://cozumpark.com/author/cengizyilmaz
# https://cengizyilmaz.com.tr
# [email protected]
#
##################################################################################################################
#>
Add-PSSnapin Microsoft.Exchange.Management.PowerShell.SnapIn
# Set the database, threshold, from, server, port, to, subject and body variables
$Database = "DB01"
$DirPath = "C:Quota"
$Threshold = "5"
$From = "[email protected]"
$Server = "mail.cengizyilmaz.net
$Port = 587
$To = "[email protected]"
$Subject = "Journal Mailbox Kota Uyarısı!"
$Body = "<html><body><h4>$database içerisinde bulunan hesapların kota durumu %$threshold değerinden fazladır.</h4><table border='3'><tr><th>Display Name</th><th>Email Address</th><th>Quota Usage</th></tr>"
$DirPathCheck = Test-Path -Path $DirPath
If (!($DirPathCheck))
{
Try
{
New-Item -ItemType Directory $DirPath -Force
}
Catch
{
$_ | Out-File ($DirPath + "" + "Log.txt") -Append
}
}
#CredObj path
$CredObj = ($DirPath + "" + "Quota.cred")
#Check if CredObj is present
$CredObjCheck = Test-Path -Path $CredObj
If (!($CredObjCheck))
{
"$Date - INFO: creating cred object" | Out-File ($DirPath + "" + "Log.txt") -Append
#SMTP Info
$Credential = Get-Credential -Message "Please enter your Mail Server credential that you will use to send e-mail $fromAddress. If you are not using the account $fromAddress make sure this account has 'Send As' rights on $FromEmail."
#Export cred obj
$Credential | Export-CliXml -Path $CredObj
}
Write-Host "Importing Cred object..." -ForegroundColor Yellow
$Cred = (Import-CliXml -Path $CredObj)
# Get all mailbox users in the specified database
$mailboxUsers = Get-Mailbox -Database $Database -ResultSize unlimited | Where-Object {$_.RecipientTypeDetails -eq 'UserMailbox'}
# Loop through each mailbox user
foreach ($user in $mailboxUsers) {
# Get the mailbox statistics
$mailbox = Get-MailboxStatistics -Identity $user.DistinguishedName
# Calculate the quota usage percentage
$quotaUsage = ($mailbox.TotalItemSize.Value.ToMB() / $user.ProhibitSendQuota.Value.ToMB()) * 100
# Check if the quota usage exceeds the threshold
if ($quotaUsage -ge $Threshold) {
# Create the HTML table row with the user's display name, email address, and quota usage in red text
$Body += "<tr><td>$($user.DisplayName)</td><td>$($user.PrimarySmtpAddress)</td><td><font color='red'>$($quotaUsage.ToString("0.00"))%</font></td></tr>"
# Create mail message object
$message = New-Object System.Net.Mail.MailMessage
$message.From = $From
$message.To.Add($To)
$message.Subject = $subject
$message.Body = $body
$message.Priority = "High"
$message.IsBodyHtml = $true
}
}
# Close HTML table and body
$Body += "</table></body></html>"
# Create the SMTP client object
$client = New-Object System.Net.Mail.SmtpClient
$client.Host = $Server
$client.Port = $Port
$client.Credentials = $Cred
# Send the email
$client.Send($message)
# Dispose of the message object
$message.Dispose()