我在线找到了一些PoSH功能,它将返回最小的交换数据库。在测试脚本时,我发现它不能按预期工作;返回的最小数据库实际上并不正确。
这是代码:
#http://izzy.org/scripts/Exchange/Admin/Create-Mailbox.ps1
$DBFilter = "MBX_*" # Limit databases to only those that start with "Primary"
Function Get-SmallestDB {
Try {
$MBXDbs = Get-MailboxDatabase | ? {$_.Identity -like $DBFilter }
$MBXDBCount = $PSSessions.Count
}
Catch {
$MBXDBCount = 0
}
If (!$MBXDbs) {ExitScript "find databases with a name that matches a filter of [$DBFilter]." $False}
# Loop through each of the MBXDbs
ForEach ($MBXDB in $MBXDbs) {
# Get current mailboxes sizes by summing the size of all mailboxes and "Deleted Items" in the database
$TotalItemSize = Get-MailboxStatistics -Database $MBXDB | %{$_.TotalItemSize.Value.ToMB()} | Measure-Object -sum
$TotalDeletedItemSize = Get-MailboxStatistics -Database $MBXDB.DistinguishedName | %{$_.TotalDeletedItemSize.Value.ToMB()} | Measure-Object -sum
$TotalDBSize = $TotalItemSize.Sum + $TotalDeletedItemSize.Sum
Write-Host "$MBXDB $($TotalItemSize.Sum) $($TotalDeletedItemSize.Sum) $TotalDBSize"
# Compare the sizes to find the smallest DB
If (($TotalDBSize -lt $SmallestDBsize) -or ($SmallestDBsize -eq $null)) {
$SmallestDBsize = $DBsize
$SmallestDB = $MBXDB }}
return $SmallestDB }
基本上,当我在Exchange环境中运行它时,它返回“MBX_20”作为$ SmallestDB。但是我添加了一些调试代码(Write-Host到$($ TotalItemSize.Sum,$($ TotalDeletedItemSize.Sum)和$ TotalDBSize的输出值,结果是:
MBX_1 140561 5180 145741
MBX_2 190865 15882 206747
MBX_3 174393 1714 176107
MBX_4 122362 6479 128841
MBX_5 108833 15409 124242
MBX_6 196569 13793 210362
MBX_7 114298 2144 116442
MBX_8 140896 21558 162454
MBX_9 160024 13364 173388
MBX_10 188268 6046 194314
MBX_11 132256 15300 147556
MBX_12 173262 6486 179748
MBX_13 101107 3761 104868
MBX_14 131453 4930 136383
MBX_15 134682 4424 139106
MBX_16 146767 12484 159251
MBX_17 155224 2074 157298
MBX_18 117147 12270 129417
MBX_19 129101 6597 135698
MBX_20 134675 9059 143734
正如您所看到的,带有143734的MBX_20不是最小的数据库。我现在正在尝试修复代码,但我对PoSH并不是很好。有什么提示吗?
答案 0 :(得分:0)
从我的评论中,我认为这是一个错字和
$SmallestDBsize = $DBsize
应该是
$SmallestDBsize = $TotalDBSize