troubleshooting Question

Export Mailboxes to PST in bulk, but in batches

Avatar of David Sankovsky
David SankovskyFlag for Israel asked on
PowershellExchangeActive Directory
2 Comments1 Solution23 ViewsLast Modified:
Dear Experts, I'm taking over a client that has recently migrated to a new EXCH 19 installation which went smoothly but is cluttered with old and unused mailboxes which belong to disabled users.
I have identified said mailboxes rather easily using the following script:

$Mailboxes = Get-Mailbox -ResultSize Unlimited | where {$_.RecipientTypeDetails -eq 'UserMailbox'}

Foreach ($Mailbox in $Mailboxes) {
    if((Get-ADUser -Identity $Mailbox.SamAccountName).Enabled -eq $False){
        $count += 1
        #$Disabled += Get-MailboxStatistics $Mailbox.SamAccountName | Select -Property DisplayName,TotalItemSize,samaccountname,alias
        $Disabled += [pscustomobject]@{    
            "Username" = $Mailbox.SamAccountName
            "Alias" = $Mailbox.Alias
            "Display Name" = (Get-MailboxStatistics $Mailbox.SamAccountName).DisplayName
            "Total Item Size (MB)" = (Get-MailboxStatistics $Mailbox.SamAccountName).TotalItemSize.Value.ToMB()
$Disabled | Export-Csv -Path $env:userprofile\desktop\DisabledADUserwithMailbox.csv -NoTypeInformation -Encoding UTF8
Write-Host "Found" $count "Mailboxes of Disabled Users"

Open in new window

So far is the easy part.
What I'm looking to do is to modify said script so that for every mailbox's samaccountname, The script will check AD Extention attribute Numer 10 - if it has the word "Exported" in it, skip said mailbox - otherwise, export the mailbox to a PST and after completion edit the Extention Attribute Number 10 to say "Exported"

Also, I don't want to to immediately export all mailboxes found as it is over 1K mailboes and I fear it will kill the storage's IOpS capacity, so I'd like to somehow limit it to 5 simultaneous exports while the rest wait in a queue if that makes sense
System Admin

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Log in to continue reading
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform for $9.99/mo
View membership options
Unlock 1 Answer and 2 Comments.
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
The Value of Experts Exchange in My Daily IT Life

Experts Exchange (EE) has become my company's go-to resource to get answers. I've used EE to make decisions, solve problems and even save customers. OutagesIO has been a challenging project and... Keep reading >>


Owner of Outages.IO
Phoenix, Arizona, United States
Member Since 2016
Join a full scale community that combines the best parts of other tools into one platform.
Unlock 1 Answer and 2 Comments.
View membership options
“All of life is about relationships, and EE has made a virtual community a real community. It lifts everyone's boat.”
William Peck

Member since 2004