We willen mailboxen in Exchange Server krijgen waarvan de totale grootte kleiner is dan het opgegeven aantal. Dit is een uitstekende manier voordat we de mailboxen naar een andere database migreren. In dit artikel leert u hoe u mailboxen kunt exporteren die kleiner zijn dan de totale grootte.
Exporteer postvakken die kleiner zijn dan de totale grootte van het PowerShell-script
De Export-MailboxesTotalSize.ps1 haalt alle mailboxen op die kleiner zijn dan de totale somgrootte die u in het script definieert. Voor elke mailbox verzamelt het de volgende informatie:
- Weergavenaam
- Totale GrootteGB
- GebruikerPrincipalName
- Primair SMTP-adres
- SMTPaliasadressen
Opmerking:Als u in het script een totale grootte van 100 GB definieert en twee mailboxen zijn 50 GB groot, worden alleen deze twee mailboxen weergegeven. Dat komt omdat het samenvatten van beide mailboxen in totaal 100 GB bedraagt.
Export-MailboxesTotalSize PowerShell-script voorbereiden
Maak twee mappen op de Exchange Server(C:)drijfveer:
- Temp
- Scripts
Download en plaats Export-MailboxesTotalSize.ps1 PowerShell-script inC:scriptsmap. Het script exporteert het CSV-bestand naar hetC:tempmap.
Zorg ervoor dat het bestand is gedeblokkeerd om fouten bij het uitvoeren van het script te voorkomen. Lees meer in het artikel Fout niet digitaal ondertekend bij het uitvoeren van PowerShell-script.
VERWANT:Blokkeer inloggen vanuit gedeelde mailboxen
Een andere optie is om de onderstaande code te kopiëren en in Kladblok te plakken. Geef het de naamExport-mailboxenTotalSize.ps1en plaats deze in deC:scriptsmap.
<#
.SYNOPSIS
Export-MailboxesTotalSize.ps1
.DESCRIPTION
Export mailboxes that are less than the defined total size.
.LINK
www.alitajran.com/export-mailboxes-total-size-less-than/
.NOTES
Written by: ALI TAJRAN
Website: www.alitajran.com
LinkedIn: linkedin.com/in/alitajran
.CHANGELOG
V1.00, 10/22/2023 - Initial version
#>
# Define the target total size in GB
$targetTotalSizeGB = 100
# Specify the mailbox database name to search within
$mailboxDatabaseName = "DB01"
# Define the export file path
$exportFilePath = "C:tempMailboxes.csv"
# Get a list of mailbox sizes within the specified mailbox database
$mailboxSizes = Get-Mailbox -ResultSize Unlimited -Database $mailboxDatabaseName |
Get-MailboxStatistics |
Select-Object DisplayName, @{Name = "TotalItemSizeGB"; Expression = { [math]::Round($_.TotalItemSize.Value.ToBytes() / 1GB, 2) } } |
Sort-Object TotalItemSizeGB
# Initialize variables
$Report = [System.Collections.Generic.List[Object]]::new()
$currentTotalSizeGB = 0
# Iterate through mailboxes to find a combination that adds up to the target total size
foreach ($mailbox in $mailboxSizes) {
$mailboxSizeGB = $mailbox.TotalItemSizeGB
# Check if adding this mailbox keeps the total size within or equal to the target size
if (($currentTotalSizeGB + $mailboxSizeGB) -le $targetTotalSizeGB) {
$selectedMailbox = Get-Mailbox $mailbox.DisplayName -ResultSize Unlimited
$upn = $selectedMailbox.UserPrincipalName
$smtpPrimary = $selectedMailbox.PrimarySmtpAddress
$smtpAliases = $selectedMailbox.EmailAddresses | Where-Object { $_.PrefixString -eq "smtp" -and $_.SmtpAddress -ne $smtpPrimary } | ForEach-Object { $_.SmtpAddress }
$ReportLine = [PSCustomObject]@{
'DisplayName' = $mailbox.DisplayName
'TotalSizeGB' = $mailbox.TotalItemSizeGB
'UserPrincipalName' = $upn
'PrimarySmtpAddress' = $smtpPrimary
'SMTPAliasAddresses' = $smtpAliases -join ", "
}
# Add the report line to the List
$Report.Add($ReportLine)
# Check if the current total size equals the target size or exceeds it
if ($currentTotalSizeGB -ge $targetTotalSizeGB) {
break
}
}
}
# Display the selected mailboxes in an interactive table
$Report | Sort-Object TotalSizeGB -Descending | Out-GridView -Title "Selected Mailboxes"
Write-Host "Total Size: $currentTotalSizeGB GB" -ForegroundColor Cyan
# Export the selected mailboxes to a CSV file
$Report | Sort-Object TotalSizeGB -Descending | Export-Csv -Path $exportFilePath -NoTypeInformation -Encoding UTF8
# Display a message indicating successful export
Write-Host "File exported successfully to $exportFilePath" -ForegroundColor Green- Regel 21:Bewerk de totale grootte
- Regel 24:Bewerk de databasenaam
- Regel 27:Bewerk het export-CSV-bestandspad
Voer Export-MailboxesTotalSize PowerShell-script uit
Voer Exchange Management Shell uit als beheerder. Wijzig het pad naar de map scripts. Voer daarna het script Export-MailboxesTotalSize.ps1 uit.
PS C:> cd c:scripts
PS C:scripts> .Export-MailboxesTotalSize.ps1De uitvoer toont de totale grootte in GB die is verzameld.
Total Size: 1.18 GBControleer mailboxen in Out-GridView
EenOut-GridViewtoont kolommen met de mailboxen en hun totale grootte in GB.

Open mailboxen rapporteren CSV-bestand
Het PowerShell-script Export-MailboxesTotalSize.ps1 exporteert de mailboxen die kleiner zijn dan de totale grootte naar een CSV-bestand. Zoek het bestand Mailboxes.csv in het padC:temp.
Open het CSV-bestand met uw favoriete applicatie. In dit voorbeeld is dit Microsoft Excel.

De brievenbussen die kleiner zijn dan het totale formaatrapport zien er geweldig uit.
Opmerking:Wilt u alle mailboxen naar een CSV-bestand exporteren en de volledige mailboxgrootte en meer informatie krijgen? Lees het artikel Postvakgrootte van alle gebruikers in Exchange verkrijgen met PowerShell.
Conclusie
U hebt geleerd hoe u met Powershell mailboxen kunt exporteren die kleiner zijn dan de totale grootte. Haal het rapport met de postvakken die kleiner zijn dan de totale grootte op met het PowerShell-script Export-MailboxesTotalSize.ps1 en bekijk het goed.
Vond je dit artikel leuk? Misschien vind je het ook leuk om Exchange-mailboxen met CSV-bestand te migreren. Vergeet ons niet te volgen en dit artikel te delen.














