Link to home
Start Free TrialLog in
Avatar of Elad-a
Elad-a

asked on

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

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

Avatar of kdagli
kdagli

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".



Avatar of Elad-a

ASKER

"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.

 
ASKER CERTIFIED SOLUTION
Avatar of Chris Dent
Chris Dent
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial