How to export the Exchange MailboxStatistics along with PrimarySmtpAddress to .CSV?

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.
This topic is 5 years and 7 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
ITEngineer
Posts: 216
Last visit: Thu Mar 23, 2023 5:45 pm
Has voted: 4 times

How to export the Exchange MailboxStatistics along with PrimarySmtpAddress to .CSV?

Post by ITEngineer »

I need some assistance to modify the script below to display one more column called PrimarySmtpAddress:

Code: Select all

Get-MailboxDatabase -Server SITE3SVR-EX01 | Get-Mailbox -ResultSize Unlimited -Database "PRODSITE3-DB" |
   Get-MailboxStatistics | 
   Select DisplayName,
   		  MailboxType, `
   		  DatabaseName, `
		  ServerName, `
   		  @{name="TotalItemSize (MB)"; expression={[math]::Round(($_.TotalItemSize.ToString().Split("(")[1].Split(" ")[0].Replace(",","")/1MB),2)}}, `
          ItemCount,
          PrimarySmtpAddress |
   Sort "TotalItemSize (MB)" -Descending | Export-Csv -Path C:\Scripts\Result.csv -NoTypeInformation
Thanks in advance.
/* IT Engineer */
User avatar
mxtrinidad
Posts: 399
Last visit: Tue May 16, 2023 6:52 am

Re: How to export the Exchange MailboxStatistics along with PrimarySmtpAddress to .CSV?

Post by mxtrinidad »

You will need to explore the object properties to make sure you got the correct spelling for the column.
Simply use the " .. | Select-Object -Property * " to display all properties to the console.

Also, you could use the get-member cmdlet to explore the PSObject you have created:
For example:
$mailStat = Get-MailboxStatistics ...
$mailStat | Get-Member

This will display both .Net PSObject properties and methods in this stored object.

Any information about Get-member can be found by using:
Get-Help Get-Member -ShowWindow

Hope this help!
User avatar
ITEngineer
Posts: 216
Last visit: Thu Mar 23, 2023 5:45 pm
Has voted: 4 times

Re: How to export the Exchange MailboxStatistics along with PrimarySmtpAddress to .CSV?

Post by ITEngineer »

Yes, you are right, there is no property in the Get-MailboxStatistics cmdlets, hence I have modified it into:

Code: Select all

Get-MailboxDatabase -Server SITE03-EX01 | Get-Mailbox -Database "PRDSITE3-DB04" -ResultSize Unlimited | 
	Select-Object DisplayName, 
	servername,database,
	RecipientTypeDetails,PrimarySmtpAddress,
	HiddenFromAddressListsEnabled,
	@{label="ItemCount";expression={(Get-MailboxStatistics $_).ItemCount}},
	@{label="TotalItemSize";expression={(Get-MailboxStatistics $_).TotalItemSize.ToString().Split("(")[1].Split(" ")[0].Replace(",","")/1MB),2}},  
	@{label="DeletedItemCount";expression={(Get-MailboxStatistics $_).DeletedItemCount}},
	@{label="TotalDeletedItemSize";expression={(Get-MailboxStatistics $_).TotalDeletedItemSize}},
	@{label="MailboxGuid";expression={(Get-MailboxStatistics $_).MailboxGuid}},
	@{label="LastLogoffTime";expression={(Get-MailboxStatistics $_).LastLogoffTime}}, 
	@{label="LastLogonTime";expression={(Get-MailboxStatistics $_).LastLogonTime}} | 
	Export-Csv -Path C:\Logs\Result.csv -NoTypeInformation
However, I am still having difficulties in the splitting the numbers?
here's the error:
At line:7 char:37
+ @{label="TotalItemSize";expression={(Get-MailboxStatistics $_).TotalItemSize.To ...
+ ~
Missing closing '}' in statement block.
At line:7 char:137
+ ... ace(",","")/1MB),2}},
+ ~
The hash literal was incomplete.
At line:7 char:137
+ ... ace(",","")/1MB),2}},
+ ~
Unexpected token ')' in expression or statement.
At line:7 char:140
+ ... (",","")/1MB),2}},
+ ~
Unexpected token '}' in expression or statement.
At line:7 char:141
+ ... ",","")/1MB),2}},
+ ~
Unexpected token '}' in expression or statement.
+ CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : MissingEndCurlyBrace
Your help is appreciated.
/* IT Engineer */
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: How to export the Exchange MailboxStatistics along with PrimarySmtpAddress to .CSV?

Post by jvierra »

Code: Select all

	@{label="TotalItemSize";expression={
              $tis = (Get-MailboxStatistics $_).TotalItemSize
              $tis.ToString().Split('(')[1].Split(' ')[0].Replace(',','')/1MB
        }},  
User avatar
ITEngineer
Posts: 216
Last visit: Thu Mar 23, 2023 5:45 pm
Has voted: 4 times

Re: How to export the Exchange MailboxStatistics along with PrimarySmtpAddress to .CSV?

Post by ITEngineer »

It runs very slow but, yes, that works Mr. Vierra :)

Thanks for the help in correcting the code.
/* IT Engineer */
This topic is 5 years and 7 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked