Avatar of fireguy1125
fireguy1125
 asked on

Exchange 2010 List Folders in Mailbox Powershell

I need to run a query on all mailboxes in my Exchange 2010 environment.  I found one that accomplishes what I need, however it is throwing an error when I run it.

Get-Mailbox -ResultSize Unlimited | Select-Object alias | foreach-object {Get-MailboxFolderStatistics -Identity $_.alias | select-object Identity, ItemsInFolder, FolderSize} | Export-csv c:\MBFolderStats.csv -NoTypeInformation

Open in new window


Produces error:

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

Open in new window


I need help re-writing it as apparently the following is the cause:

This error is caused because the Windows PowerShell remoting feature doesn’t
support more than one pipeline running at the same time. To resolve this
issue, store the output of the cmdlet earlier in the pipeline in a variable,
and then pipe the data stored in the variable to the ForEach cmdlet.

Thanks in advance!
PowershellExchange

Avatar of undefined
Last Comment
achaldave

8/22/2022 - Mon
achaldave

Try
Get-Mailbox -ResultSize Unlimited |  foreach-object {Get-MailboxFolderStatistics -Identity $_.identity | select-object Identity, ItemsInFolder, FolderSize} | Export-csv c:\MBFolderStats.csv -NoTypeInformation

If it doesn't work try,
$Mailboxes = $ Get-Mailbox -ResultSize Unlimited
$Mailboxes  |  foreach-object {Get-MailboxFolderStatistics -Identity $_.identity | select-object Identity, ItemsInFolder, FolderSize} | Export-csv c:\MBFolderStats.csv -NoTypeInformation

http://technet.microsoft.com/en-us/library/dd351136.aspx
fireguy1125

ASKER
Neither of those works:

For the 1st one, I still get the pipeline error

For the 2nd one, I get the following:

[PS] C:\Windows\system32>$Mailboxes = $ Get-Mailbox -ResultSize Unlimited
The term '$' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling
included, verify that the path is correct and try again.
At line:1 char:15
+ $Mailboxes = $ <<<<  Get-Mailbox -ResultSize Unlimited
    + CategoryInfo          : ObjectNotFound: ($:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

[PS] C:\Windows\system32>$Mailboxes  |  foreach-object {Get-MailboxFolderStatistics -Identity $_.identity | select-obje
derSize} | Export-csv c:\MBFolderStats.csv -NoTypeInformation
Cannot bind argument to parameter 'Identity' because it is null.
    + CategoryInfo          : InvalidData: (:) [Get-MailboxFolderStatistics], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Get-MailboxFolderStatistics

Open in new window

achaldave

My mistake, remove $ before get-mailbox command
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
ASKER CERTIFIED SOLUTION
suriyaehnop

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
achaldave

Solution provided by @suriyaehnop's should work, didn't realized  select-objet is within foreach-object section when I replied. if $_.alias doesn't work, replace it with $_.identity.
Both method in my previous post should look like below
Get-Mailbox -ResultSize Unlimited |  foreach-object {Get-MailboxFolderStatistics -Identity $_.identity} | select-object Identity, ItemsInFolder, FolderSize | Export-csv c:\MBFolderStats.csv -NoTypeInformation

 If it doesn't work try,
 $Mailboxes =  Get-Mailbox -ResultSize Unlimited
 $Mailboxes  |  foreach-object {Get-MailboxFolderStatistics -Identity $_.identity}  | select-object Identity, ItemsInFolder, FolderSize | Export-csv c:\MBFolderStats.csv -NoTypeInformation