Hello everyone,
I’m a newbee on powershell, i use the product for years, but since 3 months I have started to create scripts for my work… It’s hard because i don’t have the “basics”, but i enjoy Powershell.
Currently we need metrics for a new service, and I am working on a script which counts all the mails sent to different recipients on the day past.
I get the good values, and now i would like to export it on CSV format.
$Datecount = (Get-Date).AddDays(-1).ToString(“MM/dd/yyyy”)
$MailboxSRV = Get-MailboxServer | ? {$.name -match “EXCHANGE[1]0[12]”} | Sort-Object Name
$Recipients = Get-MailContact -OrganizationalUnit domain.prv/MSG/Contacts -Filter * | Where-Object {$.Name -like “NEW-SERVICE*”}Export
foreach ($Contact in $Recipients)
{
$Count = foreach ($Server in $MailboxSRV)
{
(Get-MessageTrackingLog -Server $Server.Name -Recipients ($contact | select -ExpandProperty PrimarySmtpAddress | %{[string] $x = $_ ; $x}) -Start $Datecount" 00:00:00" -End $Datecount" 23:59:59" -ResultSize unlimited | ? {$_.Source -eq “SMTP”}).count
}
$Sum = $Count | Measure-Object -Sum | Select Sum
Write-Host $contact
Write-Host $Sum
}
And i get this result :
NEW-SERVICE-1
@{Sum=0}
NEW-SERVICE-2
@{Sum=0}
NEW-SERVICE-3
@{Sum=51}
The result I want on CSV :
NEW-SERVICE-1;0
NEW-SERVICE-2;0
NEW-SERVICE-3;51
Thanks in advance!