Basically you're going to want to create a new variable that holds the results of
Get-Mailbox -database Accounting)
Then you can determine batch numbers programmatically using a percentage of the count of that variable or a specific number.
$myEmailBoxes = Get-Mailbox -database Accounting
$myEmailBoxes.count
should give you how many mailboxes are in the list total. This may not be the exact syntax for exchange powershell though. While you're testing you may want to Echo
the results to the output so you know that you are getting what you expect.
To batch the transactions use a 'for' loop instead of a for each and set it to the number you want to batch.
It would look something like the following:
$allMailboxes = Get-Mailbox -database Adjunct
$batchSize = 2
$currentBatchIndex = 0
$currentBatchMailboxes
# Call the function to start the process
batchMailboxes
function batchMailboxes {
for (i = $currentBatchIndex; i < $currentBatchIndex + $batchSize; i++)
{
$currentBatchMailboxes += $allMailboxes[i]
$currentBatchIndex++
}
exportBatchedMailboxes($currentBatchMailboxes)
$batchStatus = getBatchedMailboxStatus($currentBatchMailboxes)
if ($batchStatus == false) {
#Execute timer to get getBatchedMailboxStatus($currentBatchMailboxes)
}
else {
if ($currentBatchIndex < $allMailboxes.count - 1) {
batchMailboxes
}
}
}
function exportBatchedMailboxes ($exportMailboxes)
{
foreach ($i in $exportMailboxes) {
New-MailboxExportRequest -Mailbox $i -FilePath "backuplocation\Adjunct\$($i.Alias).pst" -baditemlimit 50 -acceptlargedataloss
}
}
function getBatchedMailboxStatus ($batch)
{
# command for checking status needs to go here using a foreach loop
}
Here's a full implementation of the script that works perfectly http://blog.bluepegasusinc.com/index.php/batch-export-exchange-2010-mailbox-to-pst/