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) [],
    + FullyQualifiedErrorId : RemotePipelineExecutionFailed
Who is Participating?
SreRajConnect With a Mentor Commented:
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}

Please try it without the foreach loop.

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

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

NytramAuthor Commented:
I know this may be silly how do you run this?
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.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.