Send Get-EXOMailbox in email

Esteemed,
I have the following Script that brings me mailboxes above a certain size, I would like to send this result in the email, I have the email script but I am not able to deploy.

Result:

Connect-ExchangeOnline -UserPrincipalName teste@*****
Get-EXOMailbox -ResultSize Unlimited | Get-EXOMailboxStatistics | Where-Object {[int64]($PSItem.TotalItemSize.Value -replace '.+\(|bytes\)') -gt "40GB"} | Sort-Object TotalItemSize -Descending | Select-Object DisplayName, ItemCount, TotalItemSize

email script:

$EmailFrom = “teste@******”
$EmailTo = “teste@*******”
$Subject = “teste *****”
$Body = “teste *****”
$SMTPServer = “smtp.office365.com”
$SMTPClient = New-Object Net.Mail.SmtpClient($SmtpServer, 587)
$SMTPClient.EnableSsl = $true
$SMTPClient.Credentials = New-Object System.Net.NetworkCredential(“teste@*******”, “*******”);
$SMTPClient.Send($EmailFrom, $EmailTo, $Subject, $Body)

Great. Have a look at Send-MailMessage (Microsoft.PowerShell.Utility) - PowerShell | Microsoft Docs. It should solve your problem. Its the built-in cmdlet for this.

1 Like