Need some help in modifying Powershell script to display mailbox size ?

Hi All,

Can anyone here please assist me in how to add one more which can display the size of the mailbox size in MB?

Here's the script that I was able to execute it successfully to display all mailboxes with the last sent items older than 90 days (customizable):

 

$xDays = 90 

Get-Mailbox -ResultSize Unlimited -RecipientTypeDetails UserMailbox | Foreach-Object {

         $si = Get-MailboxFolderStatistics $_ -IncludeOldestAndNewestItems -FolderScope SentItems 

         if($si.NewestItemReceivedDate -AND (New-TimeSpan $si.NewestItemReceivedDate.ToLocalTime()).Days -ge $xDays) { 

            #$_ 

               New-Object PSObject -Property @{

                     Name = $_.Name

                     Alias = $_.Alias

                         PrimarySmtpAddress = $_.PrimarySmtpAddress

                         WhenCreated = $_.WhenCreated

                         Database = $_.Database

                      LastSentItemDate = $si.NewestItemReceivedDate 

                         LastLogonTime = $si.LastLogonTime

               } 

      } 

} | Select Name, Alias, PrimarySmtpAddress, LastSentItemDate, WhenCreated, LastLogonTime, Database | Sort LastSentItemDate | Export-Csv -Path C:\temp\Inactive90Days.csv -NoTypeInformation -UseCulture

 

I tried to add some attributes here on Bold but still not giving me any result:

$xDays = 90 

Get-Mailbox -ResultSize Unlimited -RecipientTypeDetails UserMailbox | Foreach-Object {

         $MailboxStats = Get-MailboxStatistics $_  

         $si = Get-MailboxFolderStatistics $_ -IncludeOldestAndNewestItems -FolderScope SentItems 

         if($si.NewestItemReceivedDate -AND (New-TimeSpan $si.NewestItemReceivedDate.ToLocalTime()).Days -ge $xDays) { 

            #$_ 

               New-Object PSObject -Property @{

                     Name = $_.Name

                     Alias = $_.Alias

                         PrimarySmtpAddress = $_.PrimarySmtpAddress

                         WhenCreated = $_.WhenCreated

                         Database = $_.Database

                      LastSentItemDate = $si.NewestItemReceivedDate 

                         LastLogonTime = $si.LastLogonTime

                         MailboxSize = $MailboxStats.totalitemsize.value.ToMB()

               } 

      } 

} | Select Name, Alias, PrimarySmtpAddress, LastSentItemDate, WhenCreated, LastLogonTime, Database, MailboxSize | Sort LastSentItemDate | Export-Csv -Path C:\temp\Inactive90Days.csv -NoTypeInformation -UseCulture

 

This is the error that I got:

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

So any help would be greatly appreciated.

Thanks in advance.

Parents
No Data
Reply
  • You need to place parenthesis around your Get-Mailbox commandlet:

    (Get-Mailbox -ResultSize Unlimited -RecipientTypeDetails UserMailbox)

    This will fully process the Get-Mailbox first before sending anything down the pipeline to Foreach-Object.

    Craig's answer is another way of handling this.

Children
No Data