0
votes

Hi i tried to perform a script in exchange (and exchange online) to find shared mailboxes as on topic

Get-Mailbox -ResultSize Unlimited -RecipientTypeDetails SharedMailbox | Where {(Get-MailboxStatistics $_.Id
entity).LastLogonTime -gt (Get-Date).AddDays(-60)} | Sort -Property @{e={( Get-MailboxStatistics $_.Identity).LastLogonTime}} -Descending | Select-Object DisplayName,@{n="LastLogonTime";e={(Get-Mailbo
xStatistics $_.Identity).LastLogonTime}}|Where-Object {($_.PrimarySMTPAddress -like "*.uk*")}

I got an error

Pipeline not executed because a pipeline is already executing. Pipelines cannot be executed concurrently. + CategoryInfo : OperationStopped: (Microsoft.Power...tHelperRunspace:ExecutionCmdletHelperRunspace) [], PSInvalidOperationException + FullyQualifiedErrorId : RemotePipelineExecutionFailed

I am unable to identity an error ... can you please help ?

I used below sources

http://www.thatlazyadmin.com/get-exchange-active-mailboxes/

https://www.codetwo.com/admins-blog/list-of-active-mailboxes-powershell/

1

1 Answers

1
votes

I have rearranged the parts of your query to make it work.

$Output = Foreach ($mailbox in (Get-Mailbox -ResultSize Unlimited -RecipientTypeDetails SharedMailbox |
    Where-Object {$_.PrimarySMTPAddress -like "*.uk*"})) {
        $stats = $null
        $stats = Get-MailboxStatistics $mailbox.UserPrincipalName |
            Where-Object {$_.LastLogonTime -gt (Get-Date).Adddays(-60)}
        $stats | Sort-Object LastLogonTime -Descending |
            Select-Object DisplayName,LastLogonTime
}
$Output # Outputs to the console

This should be faster simply because it reduces the number of times you have run Get-MailboxStatistics. $Output stores the final query results, which you can access by just typing the variable name. Outputting as each object is processed (unlike what we are doing here) is painfully slow.