Page 1 of 1
How to export the Exchange MailboxStatistics along with PrimarySmtpAddress to .CSV?
Posted: Mon Aug 13, 2018 3:22 am
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.
Re: How to export the Exchange MailboxStatistics along with PrimarySmtpAddress to .CSV?
Posted: Mon Aug 13, 2018 3:51 am
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!
Re: How to export the Exchange MailboxStatistics along with PrimarySmtpAddress to .CSV?
Posted: Mon Aug 13, 2018 3:56 am
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.
Re: How to export the Exchange MailboxStatistics along with PrimarySmtpAddress to .CSV?
Posted: Mon Aug 13, 2018 4:49 am
by jvierra
Code: Select all
@{label="TotalItemSize";expression={
$tis = (Get-MailboxStatistics $_).TotalItemSize
$tis.ToString().Split('(')[1].Split(' ')[0].Replace(',','')/1MB
}},
Re: How to export the Exchange MailboxStatistics along with PrimarySmtpAddress to .CSV?
Posted: Mon Aug 13, 2018 6:32 am
by ITEngineer
It runs very slow but, yes, that works Mr. Vierra
Thanks for the help in correcting the code.