Solved

Powershell to export mailboxes

Posted on 2014-09-17
7
496 Views
Last Modified: 2014-09-22
I am running the below command. I am poor in powershell.  Is it possible to loop the next command only after completing the first one?  
foreach ($i in (Get-Mailbox)) { New-MailboxExportRequest -Mailbox $i -FilePath "\\ExchPST\September\$($i.Alias).pst" -baditemlimit 50 -acceptlargedataloss }

Open in new window


Or at-least is t possible to give a time delay (e.g. sleeptimer, start-sleep) between each loop command?
0
Comment
Question by:-MAS
  • 4
  • 3
7 Comments
 
LVL 40

Assisted Solution

by:Subsun
Subsun earned 500 total points
ID: 40327439
Try..
foreach ($i in (Get-Mailbox)) { 

New-MailboxExportRequest -Mailbox $i -FilePath "\\ExchPST\September\$($i.Alias).pst" -baditemlimit 50 -acceptlargedataloss 

while ((Get-MailboxExportRequest -Identity $i | ? {$_.Status -eq “Queued” -or $_.Status -eq “InProgress”}))  { sleep 60 }
}

Open in new window

Above command will wait until the mailbox export request get completed. If you just want to insert a 60 sec delay after once user export, then use the following code..

foreach ($i in (Get-Mailbox)) { New-MailboxExportRequest -Mailbox $i -FilePath "\\ExchPST\September\$($i.Alias).pst" -baditemlimit 50 -acceptlargedataloss;Start-Sleep 60}

Open in new window

0
 
LVL 24

Author Comment

by:-MAS
ID: 40327454
This is the error on the first command, Is it a single line command ? I tried both
A positional parameter cannot be found that accepts argument 'while'.
    + CategoryInfo          : InvalidArgument: (:) [New-MailboxExportRequest], ParameterBindingException
    + FullyQualifiedErrorId : PositionalParameterNotFound,New-MailboxExportRequest

Second one is working
0
 
LVL 40

Assisted Solution

by:Subsun
Subsun earned 500 total points
ID: 40327457
First code should be used as it is, don't combine the commands and make in in single line.. If you want to make it in single line then use ; (semicolon) to separate the commands.

foreach ($i in (Get-Mailbox)) { New-MailboxExportRequest -Mailbox $i -FilePath "\\ExchPST\September\$($i.Alias).pst" -baditemlimit 50 -acceptlargedataloss ;while ((Get-MailboxExportRequest -Identity $i | ? {$_.Status -eq “Queued” -or $_.Status -eq “InProgress”})) { sleep 60 } }

Open in new window

0
Promote certifications in your email signature

Has your company recently won an award or achieved a certification? They'll no doubt want to show it off. Email signature images used to promote certifications & awards can instantly establish credibility with a recipient and provide you with numerous benefits.

 
LVL 24

Author Comment

by:-MAS
ID: 40327465
Name                                                                 Mailbox                                                                  Status
----                                                                         -------                                                                      ------
MailboxExport                                  Domain.com/users/Joseph Scaria                                    Queued
Cannot process argument transformation on parameter 'Identity'. Cannot convert the "Joseph Scaria" value of type "
Microsoft.Exchange.Data.Directory.Management.Mailbox" to type "Microsoft.Exchange.Management.RecipientTasks.MailboxExpo
rtRequestIdParameter".
    + CategoryInfo          : InvalidData: (:) [Get-MailboxExportRequest], ParameterBindin...mationException
    + FullyQualifiedErrorId : ParameterArgumentTransformationError,Get-MailboxExportRequest

It created the first request and showing this error.
If I am not mistaken identity is supposed to be "Joseph scaria\mailboxexport"
That is why it is showing error
0
 
LVL 40

Expert Comment

by:Subsun
ID: 40327471
I am unable to test it right now.. What if you try..
foreach ($i in (Get-Mailbox)) { New-MailboxExportRequest -Mailbox $i -FilePath "\\ExchPST\September\$($i.Alias).pst" -baditemlimit 50 -acceptlargedataloss ;while ((Get-MailboxExportRequest -Identity $i.alias | ? {$_.Status -eq “Queued” -or $_.Status -eq “InProgress”})) { sleep 60 } }

Open in new window

Or
foreach ($i in (Get-Mailbox)) {$move = New-MailboxExportRequest -Mailbox $i -FilePath "\\ExchPST\September\$($i.Alias).pst" -baditemlimit 50 -acceptlargedataloss ;while ((Get-MailboxExportRequest -Identity $move.Mailbox | ? {$_.Status -eq “Queued” -or $_.Status -eq “InProgress”})) { sleep 60 } }

Open in new window

0
 
LVL 24

Accepted Solution

by:
-MAS earned 0 total points
ID: 40327498
I managed to get it done by this command. Thanks a lot.
foreach ($i in (Get-Mailbox)) { New-MailboxExportRequest -Mailbox $i -FilePath "\\ExchPST\September\$($i.Alias).pst" -baditemlimit 50 -acceptlargedataloss ;while ((Get-MailboxExportRequest -mailbox $i | ? {$_.Status -eq “Queued” -or $_.Status -eq “InProgress”})) { sleep 60 } }

Open in new window

0
 
LVL 24

Author Closing Comment

by:-MAS
ID: 40336167
Thanks
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

We are happy to announce a brand new addition to our line of acclaimed email signature management products – CodeTwo Email Signatures for Office 365.
This process describes the steps required to Import and Export data from and to .pst files using Exchange 2010. We can use these steps to export data from a user to a .pst file, import data back to the same or a different user, or even import data t…
In this video we show how to create a mailbox database in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.: First we need to log into the Exchange Admin Center. Navigate to the Servers >> Data…
This video discusses moving either the default database or any database to a new volume.

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now