Solved

Help with Get-messagetrackinglog

Posted on 2009-04-11
7
3,730 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
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.

Chris
0
 

Author Comment

by:Elad-a
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
$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
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:

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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 

Author Comment

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

Accepted Solution

by:
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?

Chris
0
 

Author Comment

by:Elad-a
ID: 24158557
Thanks Man! thats great!!
0
 

Author Closing Comment

by:Elad-a
ID: 31569187
Thanks to Chris-Dent!
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Lotus Notes – formerly IBM Notes – is an email client application, while IBM Domino (earlier Lotus Domino) is an email server. The client possesses a set of features that are even more advanced as compared to that of Outlook. Likewise, IBM Domino is…
Follow this checklist to learn more about the 15 things you should never include in an email signature from personal quotes, animated gifs and out-of-date marketing content.
The viewer will learn how to count occurrences of each item in an array.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

828 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