[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now


Help with Get-messagetrackinglog

Posted on 2009-04-11
Medium Priority
Last Modified: 2012-05-06
I need help with creating a script that would query the message tracking log and output to a file- wich is simple and I have thatrunning.The problem is that is that I have a large amount of aliases to query, so for now I have the code snippit below,  per alias.
Thing is I have 300 aliases to go through and the process is clumzy and slow.
Would you know how to abreviate the process?
For example, how would i use foreach in this instance?
Is there a way mabe to generate such a report( similar in output,without installing extra software like MOM)?

$StartDate = (get-date).AddDays(-2) 
$EndDate = (get-date).AddDays(-1)
get-messagetrackinglog -ResultSize Unlimited -EventID "RECEIVE" -Recipient:aliasname@domainname.com -Server "servername" -Start $StartDate -End $EndDate | format-table Sender, Timestamp, MessageSubject, EventID > e:\count\aliasname.txt
start-sleep -s 30
$aliasnamesub= Get-Content e:\count\aliasname.txt
$aliasnamesubject = $aliasnamesub.Length-5

Open in new window

Question by:Elad-a
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
LVL 71

Expert Comment

by:Chris Dent
ID: 24139381

It depends what you're working from. If you were working with aliases in a file something like this would work:

Get-Content "FileName.txt" | %{
  Get-MessageTrackinglog -ResultSize Unlimited -EventID "RECEIVE" `
    -Recipient $_ -Server "servername -Start $StartDate -End $EndDate

You'd end up with cleaner results if you could wait until the end of the search, it would allow the use of Export-CSV rather than just redirecting console output. e.g.

$Results = @()
Get-Content "FileName.txt" | %{
  $Results += Get-MessageTrackinglog -ResultSize Unlimited -EventID "RECEIVE" `
    -Recipient $_ -Server "servername -Start $StartDate -End $EndDate
$Results | Export-CSV "FileName.csv"

That's not the only way of course, it all depends how you'd like it to work or what you'd like it to work from.


Author Comment

ID: 24142721
This is the way id like to do it, but how'd i go about getting a result file per alias?
Also id like to do something like
$aa = Get-Content c:\Output.csv
but I get more lines in the count than acutlly exist.
How'd i incorporate that into your script?
Thanks for your help!
LVL 71

Expert Comment

by:Chris Dent
ID: 24145650

What's in Output.csv that you want to use?

> but I get more lines in the count than acutlly exist.

Trailing blank lines?

If it were a result file per alias I would do something like:

Get-Content "FileName.txt" | %{
  Get-MessageTrackinglog -ResultSize Unlimited -EventID "RECEIVE" `
    -Recipient $_ -Server "servername -Start $StartDate -End $EndDate `
    | Export-CSV "$_.csv"

If the passed alias were bob@somewhere.com the file would be called bob@somewhere.com.csv.

If the input file, "FileName.txt", is a CSV instead using Import-CSV would be more appropriate, then we would reference each field by name (assuming it has a header column).

e.g. Input file looks like:

bob@here.com,10/03/2009 12:33:12,11/03/2009 09:25:23

Then we could do:

Import-CSV "FileName.csv" | %{
  Get-MessageTrackinglog -ResultSize Unlimited -EventID "RECEIVE" `
    -Recipient $_.Alias -Server "servername -Start $_.Start -End $_.End `
    | Export-CSV "$($_.Alias).csv"


Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.


Author Comment

ID: 24151389
my reference to Output.csv was to "$_.csv".
I need to do a count of mails items per alias.
Where do the trailing blank lines come from ? is there a default number of lines (in CSV fromat)?
Thanks man for your replies, its a big help.
LVL 71

Accepted Solution

Chris Dent earned 2000 total points
ID: 24158471

The count for the CSV using Get-Content will be slightly out, at least 2 higher than the count of items returned (header line and a powershell line).

No default blank lines though, it should be accurate after that. However, perhaps we can do this:

Import-CSV "FileName.csv" | %{
  $Results = Get-MessageTrackinglog -ResultSize Unlimited -EventID "RECEIVE" `
    -Recipient $_.Alias -Server "servername -Start $_.Start -End $_.End
  $Results | Export-CSV "$($_.Alias).csv"
  $Results.Count >> "$($_.Alias).csv"

That should tack a result count onto the bottom of the CSV file (I hope). Is that what you're looking for?


Author Comment

ID: 24158557
Thanks Man! thats great!!

Author Closing Comment

ID: 31569187
Thanks to Chris-Dent!

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Want to know how to use Exchange Server Eseutil command? Go through this article as it gives you the know-how.
This month, Experts Exchange sat down with resident SQL expert, Jim Horn, for an in-depth look into the makings of a successful career in SQL.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
Suggested Courses

650 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