Solved

Help with Get-messagetrackinglog

Posted on 2009-04-11
7
3,687 Views
Last Modified: 2012-05-06
Hi,
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

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

Expert Comment

by:Chris Dent
Comment Utility

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.

Chris
0
 

Author Comment

by:Elad-a
Comment Utility
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
$aa.Length
but I get more lines in the count than acutlly exist.
How'd i incorporate that into your script?
Thanks for your help!
0
 
LVL 70

Expert Comment

by:Chris Dent
Comment Utility

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:

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

Chris
0
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 

Author Comment

by:Elad-a
Comment Utility
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.
0
 
LVL 70

Accepted Solution

by:
Chris Dent earned 500 total points
Comment Utility

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?

Chris
0
 

Author Comment

by:Elad-a
Comment Utility
Thanks Man! thats great!!
0
 

Author Closing Comment

by:Elad-a
Comment Utility
Thanks to Chris-Dent!
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Find out how to use Active Directory data for email signature management in Microsoft Exchange and Office 365.
This process describes the steps required to Import and Export data from and to .pst files using Exchange 2010. We can use these steps to export data from a user to a .pst file, import data back to the same or a different user, or even import data t…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

772 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now