I wrote PS script to collect all mailboxes from one exchange server and print in email report with mailboxdisplayname, TotalItems. stored in $Jm before formatting I want to total mailbox count and sum or TotalItems. I called another veriable $jmsummary. I got all count and sum but when i try to print that in email report -body I am not successful.
output of $JMsummary
Count : 45
Average : 20.8
Sum : 936
Maximum : 358
Minimum : 1
Property : TotalItems
here is the script
$jm
= Get-WmiObject -ComputerName <copmname> -Credential $cred
-Namespace "root/microsoftExchangev2" -Class "exchange_mailbox" |`
where {$_.mailboxdisplayname -like 'EXJ*'}
$jmsummary = ($jm | Measure-Object -Property TotalItems -Sum -Average -Maximum -Minimum )
$body = $jm | sort totalitems -Descending| ft -AutoSize |Out-String
$summary = "Total JM mailbox Count = $jmsummary.count`n+
Total JM Mailbox Email Count = $jmsummary.sum" | out-string
$fr = "EMAILID"
$to = "EMAILID"
$smtp = "SMTPservername"
Send-MailMessage -To $to -From $fr -Subject "JM status" -SmtpServer $smtp -Body "$summary $body"