Having trouble getting the below script to export column header data to a file. If I run it as it exports without column header info. When I change the last line to this it doesn't export correctly. What am I doing wrong?
$strEmails |select-object DayOfweek, Date, Sent,Sent Size,Received,Received Size |Export-Csv -Path C:\temp\PSlogs\”SentRecEmail_$(Get-Date -f 'yyyyMMdd').csv”
----------------
$From = Get-Date "09/22/2016"
$To = $From.AddDays(1)
[Int64] $intSent = $intRec = 0
[Int64] $intSentSize = $intRecSize = 0
[String] $strEmails = $null
Do
{
# Start building the variable that will hold the information for the day
$strEmails = "$($From.DayOfWeek),$($From.ToShortDateString()),"
$intSent = $intRec = 0
(Get-TransportServer | % {$_.name}) | Get-MessageTrackingLog -resultsize unlimited -Start $From -End $To | ForEach {
# Sent E-mails
If ($_.EventId -eq "RECEIVE" -and $_.Source -eq "STOREDRIVER")
{
$intSent++
$intSentSize += $_.TotalBytes
}
# Received E-mails
If ($_.EventId -eq "DELIVER")
{
$intRec++
$intRecSize += $_.TotalBytes
}
}
$intSentSize = [Math]::Round($intSentSize/1MB, 0)
$intRecSize = [Math]::Round($intRecSize/1MB, 0)
# Add the numbers to the $strEmails variable and print the result for the day
$strEmails += "$intSent,$intSentSize,$intRec,$intRecSize"
$strEmails
# Increment the From and To by one day
$From = $From.AddDays(1)
$To = $From.AddDays(1)
}
While ($To -lt (Get-Date))
$strEmails >> C:\temp\PSlogs\”SentRecEmail_$(Get-Date -f 'yyyyMMdd').csv”
Joel