M A
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?
Or at-least is t possible to give a time delay (e.g. sleeptimer, start-sleep) between each loop command?
foreach ($i in (Get-Mailbox)) { New-MailboxExportRequest -Mailbox $i -FilePath "\\ExchPST\September\$($i.Alias).pst" -baditemlimit 50 -acceptlargedataloss }
Or at-least is t possible to give a time delay (e.g. sleeptimer, start-sleep) between each loop command?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.Di rectory.Ma nagement.M ailbox" to type "Microsoft.Exchange.Manage ment.Recip ientTasks. MailboxExp o
rtRequestIdParameter".
+ CategoryInfo : InvalidData: (:) [Get-MailboxExportRequest] , ParameterBindin...mationEx ception
+ FullyQualifiedErrorId : ParameterArgumentTransform ationError ,Get-Mailb oxExportRe quest
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
---- ------- ------
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.Di
rtRequestIdParameter".
+ CategoryInfo : InvalidData: (:) [Get-MailboxExportRequest]
+ FullyQualifiedErrorId : ParameterArgumentTransform
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 } }
Orforeach ($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 } }
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks
ASKER
A positional parameter cannot be found that accepts argument 'while'.
+ CategoryInfo : InvalidArgument: (:) [New-MailboxExportRequest]
+ FullyQualifiedErrorId : PositionalParameterNotFoun
Second one is working