我有一个小问题,我想获取所有邮箱并将其放入变量中,这似乎很容易
$mailboxes = Get-Mailbox
但是我们的数据库中邮箱太多(我认为大约90k),当我使用此命令时PowerShell崩溃。如果我只有7500个邮箱,我曾想过使用邮箱分页,那么它可以工作,但是我该怎么做:
$allMailBoxes = @()
$mailboxes1 = Get-Mailbox -From 0 -To 10000
$mailboxes2 = Get-Mailbox -From 100001 -To 20000
$allMailBoxes += mailboxes1 += mailboxes2
还是我没有想到的其他解决方案?我需要每周存储此数据。我只需要数字,带有语音企业选项的数字和平均邮箱大小。
当前代码:
## EXCHANGE
$allMailBoxes = Get-Mailbox -resultsize 7500
$CountMailBoxes = $allMailBoxes.count
$CountSharedMailBoxes = (Get-Mailbox -RecipientTypeDetails SharedMailbox -ResultSize:Unlimited).count
#$CountSharedMailLists = voir flo
$CountExchangeDatabases = (Get-MailboxDatabase).Count
$MailBoxesStatistics = $allMailBoxes | Get-MailboxStatistics
$tabMailBoxesSize = @()
foreach ($Mailbox in $MailBoxesStatistics)
{
$MailboxSize = $Mailbox.TotalItemSize
for($i = 0; $i -lt $MailboxSize.Length; $i++) {
if ($MailboxSize[$i] -eq "(")
{
$indexChevron = $i
## formatted quota without the bytes : "1.9 GB <2,040,110,000 bytes>" becomes "1.9 GB"
$FormattedMailboxSize = Invoke-Expression ((($MailboxSize.Substring(0, $indexChevron-1)).replace(' ', '')))
$tabMailBoxesSize += $FormattedMailboxSize
}
}
}
$tabMailBoxesSize = $tabmailboxessize | Measure-Object -Average | select Average
$CountMailBoxesAverageSize = [math]::Round($tabmailboxesSize.Average/1GB, 2).toString() + " GB"
Write-Output "Taille moyenne des BALs : $CountMailBoxesAverageSize"