Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Powershell to export mailboxes

Posted on 2014-09-17
7
Medium Priority
?
611 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 40

Assisted Solution

by:Subsun
Subsun earned 2000 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 27

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 2000 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
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

 
LVL 27

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 27

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 27

Author Closing Comment

by:MAS
ID: 40336167
Thanks
0

Featured Post

Office 365 Training for Admins - 7 Day Trial

Learn how to provision tenants, synchronize on-premise Active Directory, implement Single Sign-On, customize Office deployment, and protect your organization with eDiscovery and DLP policies.  Only from Platform Scholar.

Question has a verified solution.

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

In the absence of a fully-fledged GPO Management product like AGPM, the script in this article will provide you with a simple way to watch the domain (or a select OU) for GPOs changes and automatically take backups when policies are added, removed o…
New style of hardware planning for Microsoft Exchange server.
In this video we show how to create a Resource Mailbox in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.: Navigate to the Recipients >> Resources tab.: "Recipients" is our default selection …
In this video we show how to create an Address List 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 Organization >> Ad…

719 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