add-pssnapin Microsoft.Exchange.Management.PowerShell.E2010

$Date = Get-Date -format 'yyyy-MM-dd HH-mm-ss'
$Fichier = "D:\Informatique\All-Mailbox-$Date.csv"
$emailAttachments = "D:\Informatique\All-Mailbox.csv"

#Get-Mailbox -ResultSize Unlimited | Select-Object Displayname,name,alias,PrimarySmtpAddress,Database,@{Name='TotalItemSize'; Expression={[String]::join(";",((Get-MailboxStatistics -identity $_.identity).TotalItemSize))}},@{Name='ItemCount'; Expression={[String]::join(";",((Get-MailboxStatistics -identity $_.identity).ItemCount))}},IssueWarningQuota, ProhibitSendQuota, ProhibitSendReceiveQuota | where-object {$_.enabled -eq $True} | export-csv -path $Fichier
Get-Mailbox -ResultSize Unlimited | Select-Object Displayname,name,alias,PrimarySmtpAddress,Database,@{Name='TotalItemSize'; Expression={[String]::join(";",((Get-MailboxStatistics -identity $_.identity).TotalItemSize))}},@{Name='ItemCount'; Expression={[String]::join(";",((Get-MailboxStatistics -identity $_.identity).ItemCount))}},IssueWarningQuota, ProhibitSendQuota, ProhibitSendReceiveQuota | export-csv -path $Fichier

$SPLA = (Get-Mailbox -ResultSize Unlimited -Filter {EmailAddresses -like "*.mailnot.fr"} ).Count

(Get-Content $Fichier) -replace '","','";"' | Set-Content "D:\Informatique\All-Mailbox-temp.csv"
(Get-Content "D:\Informatique\All-Mailbox-temp.csv") -replace ',,,',';;;' | Set-Content $emailAttachments

Start-Sleep -s 10

$emailSmtpServer = "10.101.10.2"
$emailSmtpServerPort = "25"
 
$emailFrom = "Rapports@cloud-fichorga.fr"
$emailTo   = "hcornet@fichorga.fr, ypereira@fichorga.fr, fdupont@fichorga.fr, cleroux@fichorga.fr, jmdefossez@fichorga.fr, alefevre@pmsjuris.fr, sdemarez@fichorga.fr, mdelplanche@fichorga.fr, eringuet@fichorga.fr"


$body = "<HTML><HEAD><META http-equiv=""Content-Type"" content=""text/html; charset=iso-8859-1"" /><TITLE></TITLE></HEAD>"
$body += "<BODY bgcolor=""#FFFFFF"" style=""font-size: Small; font-family: TAHOMA; color: #000000""><P>"
$body += "Bonjour <b><font color=blue>a tous</b></font><br><br>"
$body += "Voici l'extraction de l'ensemble des boites mail client a la date du <b>$Date</b>.<br>"
$body += "<br><br>"
$body += "Il y a : <b><font color=blue>$SPLA</b></font> comptes à déclarer pour le SPLA.<br>"
$body += "<br><br>"
$body += "Bonne lecture.<br><br>"
$body += "<b><font color=red>Merci de ne pas faire repondre a ce message.</b></font><br>"
$body += "Pour ne plus faire partie de la liste <a href='mailto:hcornet@fichorga.fr?Subject=Desinscription%20Rapport%20mail' target='_top'>Send Mail</a>.<br>"
 
$emailMessage = New-Object System.Net.Mail.MailMessage( $emailFrom , $emailTo )
$emailMessage.Subject = "Extraction : client CONNECT" 
$emailMessage.IsBodyHtml = $True
$emailMessage.Body = $body
$emailMessage.Attachments.add($emailAttachments)

$SMTPClient = New-Object System.Net.Mail.SmtpClient( $emailSmtpServer, $emailSmtpServerPort ) 
$SMTPClient.EnableSsl = $False
$SMTPClient.Send( $emailMessage )

Start-Sleep -s 10

Remove-Item "D:\Informatique\All-Mailbox-$Date.csv" -recurse
Remove-Item "D:\Informatique\All-Mailbox-temp.csv" -recurse
Remove-Item "D:\Informatique\All-Mailbox.csv" -recurse

