?
Solved

Help, Problems with Get-messagetrackinglog, and my script in general :-)

Posted on 2009-04-19
5
Medium Priority
?
945 Views
Last Modified: 2012-05-06
Hi,
Please assist with this script , cant find why it wont work nicely....
what I'm trying to do, is to create  an export to one HTM file, of all mail that comes in per alias.
and in return, send all users a count of his/her mail with a tracking log that is relevant to him, as described in the code below . Problem is that the Export to CSV wont work ....
Can you please comment on where I'm going wrong in the script?

("aliasname.txt" contains a list of Aliases i want to sample)


Thanks for your help.
# Date Variables & domainname
$StartDate = (get-date).AddDays(-2) 
$EndDate = (get-date).AddDays(-1) 
$b = "@domainname.com"
e:
cd count
cd scripts
cd test
 
$i = Get-Content "aliasname.txt"
Get-Content "aliasname.txt" | %{
  Get-MessageTrackinglog -ResultSize Unlimited -EventID "RECEIVE" `
    -Recipient "$_$b" -Server "servername" -Start $StartDate -End $EndDate `
    | Export-CSV "e:\scripts\$_.csv"
 
$count = Get-Content e:\scripts"$_.csv"
$namecount = $count.Length-2
Echo "Start Date,End Date,Feed Count" > e:\scripts\Report.csv
Echo "From: $StartDate, To:$EndDate ,there were $namecount E-Mail's To $_ " >> e:\scripts\report.csv
}
 
$a = "<style>"
$a = $a + "BODY{background-color:peachpuff;}"
$a = $a + "TABLE{border-width: 1px;border-style: solid;border-color: black;border-collapse: collapse;}"
$a = $a + "TH{border-width: 1px;padding: 0px;border-style: solid;border-color: black;background-color:silver}"
$a = $a + "TD{border-width: 1px;padding: 0px;border-style: solid;border-color: black;background-color:palegoldenrod}"
$a = $a + "</style>"
 
 
 
Import-Csv report.csv | Where-Object {$_.Volume -ne "0"} | ConvertTo-Html -head $a body "<H2>Mail ITem Count </H2>" | Out-File c:\scripts\htmReport.htm
 
#./send-mail.ps1 -server smtpserver -from fromalias@domainname.com -to smtpalias@domain.com -subject "$_ : Yesterday there were $namecount E-mails." -body "Thanks, IT." -attachment e:\Scripts\"$_.csv" -verbose

Open in new window

0
Comment
Question by:Elad-a
3 Comments
 
LVL 4

Expert Comment

by:kdagli
ID: 24181645
The script creates an HTML report only for the last user mentioned in the Aliasname.txt file.

What is the exact problem you are facing and what is the output desired form the script also what do you mean by "Nicely".



0
 

Author Comment

by:Elad-a
ID: 24182292
"Nicely" means that id like it to work...
For starters the fist problem is that it creates a report only for the last user mentioned in Aliasname.txt while id like it  to output all mentioned users in the HTM .
The HTM should provide a count of incoming mails per alias for the previous day.
And lastly, sends a separate mail with an attachment of aliasname.csv (per alias) entailing the transaction log.
The report will be the body for a central mail going out to the users.
Thanks
Jason.

 
0
 
LVL 71

Accepted Solution

by:
Chris Dent earned 1500 total points
ID: 24213982

This line:

> Echo "Start Date,End Date,Feed Count" > e:\scripts\Report.csv

Means that report.csv is overwritten for each user rather than appending do it (as we do with >>). e.g.:

Echo "Start Date,End Date,Feed Count" >> e:\scripts\Report.csv

Where does "$_.Volume" come from? The file you're importing at the point doesn't include that.

Anyway, I would change it to something like the below (I suspect it might need tweaking a bit though).

Chris
# Date Variables & domainname
$StartDate = (get-date).AddDays(-2) 
$EndDate = (get-date).AddDays(-1) 
$b = "@domainname.com"
e:
cd count
cd scripts
cd test
 
$Report = @()
Get-Content "aliasname.txt" | %{
  $Messages = Get-MessageTrackinglog -ResultSize Unlimited -EventID "RECEIVE" `
    -Recipient "$_$b" -Server "servername" -Start $StartDate -End $EndDate
 
  $Report += "" | Select-Object @{n='Alias';e={ $_ }}, @{n='StartDate';e={ $StartDate }}, `
    @{n='EndDate';e={ $EndDate }}, @{n='MessageCount';e={ If ($Messages) { $Messages.Count } else { 0 } }}
}
 
$a = "<style>"
$a = $a + "BODY{background-color:peachpuff;}"
$a = $a + "TABLE{border-width: 1px;border-style: solid;border-color: black;border-collapse: collapse;}"
$a = $a + "TH{border-width: 1px;padding: 0px;border-style: solid;border-color: black;background-color:silver}"
$a = $a + "TD{border-width: 1px;padding: 0px;border-style: solid;border-color: black;background-color:palegoldenrod}"
$a = $a + "</style>"
 
$Report | ?{ $_.MessageCount -gt 0 } | ConvertTo-HTML -Head $a

Open in new window

0

Featured Post

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this post, I will showcase the steps for how to create groups in Office 365. Office 365 groups allow for ease of flexibility and collaboration between staff members.
Measuring Server's processing rate with a simple powershell command. The differences in processing rate also was recorded in different use-cases, when a server in free and busy states.
how to add IIS SMTP to handle application/Scanner relays into office 365.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Suggested Courses
Course of the Month16 days, 17 hours left to enroll

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question