Unable to display Mailbox size in Exchange server script ?

Ask your PowerShell-related questions, including questions on cmdlet development!
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Locked
User avatar
ITEngineer
Posts: 210
Joined: Wed Oct 12, 2011 10:52 am

Unable to display Mailbox size in Exchange server script ?

Post by ITEngineer »

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):
  1. $xDays = 90
  2.  
  3. Get-Mailbox -ResultSize Unlimited -RecipientTypeDetails UserMailbox | Foreach-Object {
  4.  
  5.          $si = Get-MailboxFolderStatistics $_ -IncludeOldestAndNewestItems -FolderScope SentItems
  6.  
  7.          if($si.NewestItemReceivedDate -AND (New-TimeSpan $si.NewestItemReceivedDate.ToLocalTime()).Days -ge $xDays) {
  8.  
  9.             #$_
  10.  
  11.                New-Object PSObject -Property @{
  12.  
  13.                      Name = $_.Name
  14.  
  15.                      Alias = $_.Alias
  16.  
  17.                          PrimarySmtpAddress = $_.PrimarySmtpAddress
  18.  
  19.                          WhenCreated = $_.WhenCreated
  20.  
  21.                          Database = $_.Database
  22.  
  23.                          LastSentItemDate = $si.NewestItemReceivedDate
  24.  
  25.                          LastLogonTime = $si.LastLogonTime
  26.  
  27.                }
  28.  
  29.       }
  30.  
  31. } | 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 to get the mailbox size in the additional column but still not giving me any result:
  1. $xDays = 90
  2.  
  3. Get-Mailbox -ResultSize Unlimited -RecipientTypeDetails UserMailbox | Foreach-Object {
  4.  
  5.          $MailboxStats = Get-MailboxStatistics $_  
  6.  
  7.          $si = Get-MailboxFolderStatistics $_ -IncludeOldestAndNewestItems -FolderScope SentItems
  8.  
  9.          if($si.NewestItemReceivedDate -AND (New-TimeSpan $si.NewestItemReceivedDate.ToLocalTime()).Days -ge $xDays) {
  10.  
  11.             #$_
  12.  
  13.                New-Object PSObject -Property @{
  14.  
  15.                      Name = $_.Name
  16.  
  17.                      Alias = $_.Alias
  18.  
  19.                          PrimarySmtpAddress = $_.PrimarySmtpAddress
  20.  
  21.                          WhenCreated = $_.WhenCreated
  22.  
  23.                          Database = $_.Database
  24.  
  25.                          LastSentItemDate = $si.NewestItemReceivedDate
  26.  
  27.                          LastLogonTime = $si.LastLogonTime
  28.  
  29.                          MailboxSize = $MailboxStats.totalitemsize.value.ToMB()
  30.  
  31.                }
  32.  
  33.       }
  34.  
  35. } | 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.
/* IT Engineer */

jvierra
Posts: 14545
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Unable to display Mailbox size in Exchange server script ?

Post by jvierra »

You cannot pipeline these commands. It must be done in separate steps.

User avatar
ITEngineer
Posts: 210
Joined: Wed Oct 12, 2011 10:52 am

Re: Unable to display Mailbox size in Exchange server script ?

Post by ITEngineer »

jvierra wrote:You cannot pipeline these commands. It must be done in separate steps.
Ah I see,

I've tried to modify it as below, it works with no error but it is still no result on the size column:
  1. $xDays = 90
  2.  
  3. Get-Mailbox -ResultSize Unlimited -RecipientTypeDetails UserMailbox | Foreach-Object {  
  4.  
  5.          $si = Get-MailboxFolderStatistics $_ -IncludeOldestAndNewestItems -FolderScope SentItems
  6.  
  7.          if($si.NewestItemReceivedDate -AND (New-TimeSpan $si.NewestItemReceivedDate.ToLocalTime()).Days -ge $xDays) {
  8.  
  9.             #$_
  10.  
  11.                New-Object PSObject -Property @{
  12.  
  13.                      Name = $_.Name
  14.  
  15.                      Alias = $_.Alias
  16.  
  17.                          PrimarySmtpAddress = $_.PrimarySmtpAddress
  18.  
  19.                          WhenCreated = $_.WhenCreated
  20.  
  21.                          Database = $_.Database
  22.  
  23.                      LastSentItemDate = $si.NewestItemReceivedDate
  24.  
  25.                          LastLogonTime = $si.LastLogonTime
  26.  
  27.                                 MailboxSize = $si.TotalItemSize
  28.  
  29.                }
  30.  
  31.       }
  32.  
  33. } | Select Name, Alias, PrimarySmtpAddress, LastSentItemDate, WhenCreated, LastLogonTime, Database, MailboxSize | Sort LastSentItemDate | ft -AutoSize
Any other suggestion perhaps?
/* IT Engineer */

jvierra
Posts: 14545
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Unable to display Mailbox size in Exchange server script ?

Post by jvierra »

You cannot convert a de-serialized ByteQuantifiedSize because it gets converted to a string.

$si.TotalItemSize.value -match '\((.*)bytes\)'
[int64]($matches[1])

User avatar
ITEngineer
Posts: 210
Joined: Wed Oct 12, 2011 10:52 am

Re: Unable to display Mailbox size in Exchange server script ?

Post by ITEngineer »

jvierra wrote:You cannot convert a de-serialized ByteQuantifiedSize because it gets converted to a string.

$si.TotalItemSize.value -match '\((.*)bytes\)'
[int64]($matches[1])
:?:

Yes, the code still nor working:
  1. $xDays = 180
  2.  
  3. Get-Mailbox -ResultSize Unlimited -RecipientTypeDetails UserMailbox | Foreach-Object {
  4.  
  5.          $si = Get-MailboxFolderStatistics $_ -IncludeOldestAndNewestItems -FolderScope SentItems
  6.  
  7.          if($si.NewestItemReceivedDate -AND (New-TimeSpan $si.NewestItemReceivedDate.ToLocalTime()).Days -ge $xDays) {
  8.  
  9.             #$_
  10.  
  11.                New-Object PSObject -Property @{
  12.  
  13.                      Name = $_.Name
  14.  
  15.                      Alias = $_.Alias
  16.  
  17.                          PrimarySmtpAddress = $_.PrimarySmtpAddress
  18.  
  19.                          WhenCreated = $_.WhenCreated
  20.  
  21.                          Database = $_.Database
  22.  
  23.                          LastSentItemDate = $si.NewestItemReceivedDate
  24.  
  25.                          LastLogonTime = $si.LastLogonTime
  26.  
  27.  [b]                        MailboxSize = $si.TotalItemSize.value -match '\((.*)bytes\)' [int64]($matches[1])[/b]
  28.  
  29.                }
  30.  
  31.       }
  32.  
  33. } | Select Name, Alias, PrimarySmtpAddress, LastSentItemDate, WhenCreated, LastLogonTime, Database, MailboxSize | Sort LastSentItemDate | Export-Csv -Path C:\temp\Inactive180Days.csv -NoTypeInformation -UseCulture
I get this error:
Unexpected token 'int64' in expression or statement.
At C:\temp\InactiveXDays.ps1:15 char:94
+ MailboxSize = $si.TotalItemSize.value -match '\((.*)bytes\)' [int64] <<<< ($matches[1])
+ CategoryInfo : ParserError: (int64:String) [], ParseException
+ FullyQualifiedErrorId : UnexpectedToken
/* IT Engineer */

jvierra
Posts: 14545
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Unable to display Mailbox size in Exchange server script ?

Post by jvierra »

You pasted everything onto one line including the HHTML formatting characters.

Locked