Link to home
Create AccountLog in
Avatar of Indyrb
IndyrbFlag for United States of America

asked on

Need Powershell script for Exchange 2007

I need help... Can i get assistance with creating a powershell script that can scan through exchange and kick out a csv file detailing the following information:
 
1 row per email received
1.       User of the mailbox
2.       Sender of the email
Avatar of Manpreet SIngh Khatra
Manpreet SIngh Khatra
Flag of India image

Get-Mailbox | Get-MessageTrackingLog | FL Sender, Recipient, Subject

- Rancy
Avatar of Indyrb

ASKER

Getting error on all users and no list is provided

The input object cannot be bound to any parameters for the command either because the command does not take pipeline in
put or the input and its properties do not match any of the parameters that take pipeline input.
    + CategoryInfo          : InvalidArgument: (User1:PSObject) [Get-MessageTrackingLog], ParameterBindingEx
   ception
    + FullyQualifiedErrorId : InputObjectNotBound,Get-MessageTrackingLog

The input object cannot be bound to any parameters for the command either because the command does not take pipeline in
put or the input and its properties do not match any of the parameters that take pipeline input.
    + CategoryInfo          : InvalidArgument: (User2:PSObject) [Get-MessageTrackingLog], ParameterBindingExce
   ption
    + FullyQualifiedErrorId : InputObjectNotBound,Get-MessageTrackingLog

The input object cannot be bound to any parameters for the command either because the command does not take pipeline in
put or the input and its properties do not match any of the parameters that take pipeline input.
    + CategoryInfo          : InvalidArgument: (User3:PSObject) [Get-MessageTrackingLog], ParameterBindingExc
   eption
    + FullyQualifiedErrorId : InputObjectNotBound,Get-MessageTrackingLog
Give me sometime and i should be on my labs and be able to assist

- Rancy
Try the following command:

Get-TransportServer | Get-MessageTrackingLog -ResultSize Unlimited -EventID DELIVER | FL Sender, Recipients, MessageSubject | Export-Csv C:\Export.csv

Sudeep
Avatar of Indyrb

ASKER

Didn't giver user mailboxs, nor sender of the email, or subjects of emails in mailbox..
instead gave this info in the  csv file.

#TYPE Microsoft.PowerShell.Commands.Internal.Format.FormatStartData                              
ClassId2e4f51ef21dd47e99d3c952918aff9cd      pageHeaderEntry      pageFooterEntry      autosizeInfo      shapeInfo      groupingEntry
033ecb2bc07a4d43b5ef94ed5a35d280                        Microsoft.PowerShell.Commands.Internal.Format.ListViewHeaderInfo      
9e210fe47d09416682b841769c78b8a3                              
27c87ef9bbda4f709f6b4002fa4af63c                              
27c87ef9bbda4f709f6b4002fa4af63c                              
27c87ef9bbda4f709f6b4002fa4af63c                              
27c87ef9bbda4f709f6b4002fa4af63c                              
27c87ef9bbda4f709f6b4002fa4af63c                              
27c87ef9bbda4f709f6b4002fa4af63c                              
27c87ef9bbda4f709f6b4002fa4af63c                              
27c87ef9bbda4f709f6b4002fa4af63c                              
27c87ef9bbda4f709f6b4002fa4af63c                              
27c87ef9bbda4f709f6b4002fa4af63c                              
27c87ef9bbda4f709f6b4002fa4af63c                              
27c87ef9bbda4f709f6b4002fa4af63c                              
27c87ef9bbda4f709f6b4002fa4af63c                              
27c87ef9bbda4f709f6b4002fa4af63c                              
27c87ef9bbda4f709f6b4002fa4af63c                              
27c87ef9bbda4f709f6b4002fa4af63c                              
27c87ef9bbda4f709f6b4002fa4af63c                              
27c87ef9bbda4f709f6b4002fa4af63c                              
27c87ef9bbda4f709f6b4002fa4af63c                              
27c87ef9bbda4f709f6b4002fa4af63c                              
27c87ef9bbda4f709f6b4002fa4af63c
The above command work flawlessly on our Exchange 2007 server. Maybe someone else would give you better idea of what's wrong.

Sudeep
Use Select-Object instead of Format-List (FL), FL will not pass the objects to powershell pipeline..
Get-TransportServer | Get-MessageTrackingLog -ResultSize Unlimited -EventID DELIVER | Select Sender, Recipients, MessageSubject | Export-Csv C:\Export.csv -NTI

Open in new window

Avatar of Indyrb

ASKER

A lot better.
I take it column one is sender. However reciepent is coming up as System.String[], can we also get the date included too?
Try..
Get-TransportServer | Get-MessageTrackingLog -ResultSize Unlimited -EventID DELIVER | Select Sender,{$_. Recipients},MessageSubject,TimeStamp | Export-Csv C:\Export.csv -NTI

Open in new window

Avatar of Indyrb

ASKER

Column "Recipents" still show System.String[] for each email
Also can we add the date?
ASKER CERTIFIED SOLUTION
Avatar of SubSun
SubSun
Flag of India image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Avatar of Indyrb

ASKER

Example, this is how it is showing up

Sender                                                           Recipients      MessageSubject

whitepapers@somedomain.com      System.String[]      Case Study
Did you try with last code?
Avatar of Indyrb

ASKER

PERFECT!!!! THANKS SO MUCH...
One last thing -- can you export the body / contents of the email into the csv file?
Which email? Are you talking about the user email? If yes, tracking log doesn't contain any information about the users email contents..

Or if you ate trying to send this command result as email then it's possible..
Avatar of Indyrb

ASKER

I meant, like the example below, can you export the email\body of the message or is there anyway to get this information

Sender                               Recipients             MessageSubject     Email Message or Body           Date
myjones@domain.com    me@another.net  Hi                             Hey, how is it going?
Nope.. You cannot get the message body information with Get-MessageTrackingLog. If you want to get the message body then you need to get it from the user mailbox.. Which is not a easy task..

If you are trying to monitor user emails the best option would be using Journaling Rules..
Ref : http://www.msexchange.org/articles-tutorials/exchange-server-2007/compliance-policies-archiving/Exchange-Server-2007-Using-Journaling-Rules.html