Solved

Powershell to export mailboxes

Posted on 2014-09-17
7
524 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 25

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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 25

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 25

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 25

Author Closing Comment

by:-MAS
ID: 40336167
Thanks
0

Featured Post

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
This article explains in simple steps how to renew expiring Exchange Server Internal Transport Certificate.
To show how to generate a certificate request 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 >> Certificates…
This video demonstrates how to sync Microsoft Exchange Public Folders with smartphones using CodeTwo Exchange Sync and Exchange ActiveSync. To learn more about CodeTwo Exchange Sync and download the free trial, go to: http://www.codetwo.com/excha…

825 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