Help with Get-messagetrackinglog

Posted on 2009-04-11
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" -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 the file would be called

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:

Alias,Start,End,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"

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.


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 500 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

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

This article lists the top 5 free OST to PST Converter Tools. These tools save a lot of time for users when they want to convert OST to PST after their exchange server is no longer available or some other critical issue with exchange server or impor…
In threads here at EE, each comment has a unique Identifier (ID). It is easy to get the full path for an ID via the right-click context menu. However, we often want to post a short link within a thread rather than the full link. This article shows a…
This video discusses moving either the default database or any database to a new volume.
This video demonstrates how to sync Microsoft Exchange Public Folders with smartphones using CodeTwo Exchange Sync and Exchange ActiveSync. To learn more about CodeTwo Exchange Sync and download the free trial, go to:…

729 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