Exchange power shell

Hi  Im running this and im sure its corrcet but its not running right so somthing is not right

Get-MailboxStatistics -Database “migrationtemp4¿ | where {$_.DisconnectReason -eq “SoftDeleted”} | foreach {Remove-StoreMailbox -Database $_.database -Identity $_.mailboxguid -MailboxState SoftDeleted}

Pipeline not executed because a pipeline is already executing. Pipelines cannot be executed concurrently.
    + CategoryInfo          : OperationStopped: (Microsoft.Power...tHelperRunspace:ExecutionCmdletHelperRunspace) [],
   PSInvalidOperationException
    + FullyQualifiedErrorId : RemotePipelineExecutionFailed
NytramAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

SreRajCommented:
Hi,

Please try it without the foreach loop.

Get-MailboxStatistics -Database “migrationtemp4" | where {$_.DisconnectReason -eq “SoftDeleted”} | Remove-StoreMailbox -Database $_.database -Identity $_.mailboxguid -MailboxState SoftDeleted
0
NytramAuthor Commented:
Hi

Not not working

Get-MailboxStatistics -Database "migrationtemp4" | where {$_.DisconnectReason -eq "SoftDeleted"} | Remove-StoreMailbox -Database $_.database -Identity $_.mailboxguid -MailboxState SoftDeleted

Cannot bind argument to parameter 'Database' because it is null.
    + CategoryInfo          : InvalidData: (:) [Remove-StoreMailbox], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Remove-StoreMailbox

Invoke-Command : Cannot write input as there are no more running pipelines
At C:\Users\xxxxx.SU\AppData\Roaming\Microsoft\Exchange\RemotePowerShell\xxxx.xx.xx\xxx.xxx.xxx.ps
m1:40567 char:29
+             $scriptCmd = { & <<<<  $script:InvokeCommand `
    + CategoryInfo          : InvalidOperation: (:) [Invoke-Command], PSInvalidOperationException
    + FullyQualifiedErrorId : NoMoreInputWrite,Microsoft.PowerShell.Commands.InvokeCommandCommand

If I run Get-MailboxStatistics -Database "migrationtemp4"  is run with the a full list of users stats

Martyn
0
SreRajCommented:
I feel it is better to break the command into two lines with the help of a variable. Please try the following code.


$SDMailboxes = Get-MailboxStatistics -Database ““migrationtemp4" | where {$_.DisconnectReason -eq “SoftDeleted”}
$SDMailboxes | foreach {Remove-StoreMailbox -Database $_.database -Identity $_.mailboxguid -MailboxState SoftDeleted}
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
NytramAuthor Commented:
I know this may be silly how do you run this?
0
SreRajCommented:
You could break it to two lines and execute it from Exchange Management Shell, one line at a time.

$SDMailboxes = Get-MailboxStatistics -Database ““migrationtemp4" | where {$_.DisconnectReason -eq “SoftDeleted”}

$SDMailboxes | foreach {Remove-StoreMailbox -Database $_.database -Identity $_.mailboxguid -MailboxState SoftDeleted}

Please copy paste first line and then press enter. So the result will be stored $SDMailboxes variable. Then you should execute the second line.

Also you could create a script file by pasting the these two lines in a text file and saving it as a .ps1 file, for example you could name it 'RemoveSoftDeleted.ps1'. Then you could execute this script from Exchange Management Shell by browsing to the path where script is stored and then give the command .\RemoveSoftDeleted.ps1

We are adding the characters .\ in front of the script file name to execute it from Exchange Management Shell.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Exchange

From novice to tech pro — start learning today.