Link to home
Start Free TrialLog in
Avatar of M A
M AFlag for United States of America

asked on

Powershell to export mailboxes

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?
SOLUTION
Avatar of SubSun
SubSun
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of M A

ASKER

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
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of M A

ASKER

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

ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of M A

ASKER

Thanks