Created
July 11, 2020 04:39
-
-
Save robderickson/c67e52b7cca15491d15c23b6b69502f3 to your computer and use it in GitHub Desktop.
TL;DR: Over-complicate Exchange database selection during mailbox provisioning. For each mailbox in a collection of Exchanges mailboxes, return PrimarySmtpAddress and the smallest database (factoring in AvailableNewMailboxSpace). As databases are selected, add the mailbox's size to the database size so the next database selected factors in the s…
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function GetMoveParameters { | |
[CmdletBinding()] | |
param( | |
[string[]]$Mailbox, | |
[string[]]$Databases | |
) | |
PROCESS { | |
if ($Databases) { | |
$dbs = $Databases | Where-Object {$_.Mounted -eq $true} | |
} else { | |
$dbs = Get-MailboxDatabase -Status | Where-Object {$_.Mounted -eq $true} | |
} | |
$DbSizes = foreach ($db in $dbs) { | |
[PSCustomObject]@{ | |
Name = $db.Name | |
Size = $db.DatabaseSize.ToBytes() - $db.AvailableNewMailboxSpace.ToBytes() | |
} | |
} | |
foreach ($mb in $Mailbox) { | |
$MbStats = Get-Mailbox $mb | Get-MailboxStatistics | |
$MbSize = $MbStats.TotalItemSize.Value.ToBytes() + $MbStats.TotalDeletedItemSize.Value.ToBytes() | |
$SmallestDatabase = $DbSizes | Sort-Object Size | Select-Object -First 1 | |
($DbSizes | Where-Object {$_.name -eq $SmallestDatabase.name}).Size = $SmallestDatabase.Size + $MbSize | |
[PSCustomObject]@{ | |
PrimarySmtpAddress = Get-Mailbox $mb | Select-Object -ExpandProperty PrimarySmtpAddress | |
TargetDatabase = $SmallestDatabase.Name | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment