Jump to content

Recommended Posts

Posted

I've got a user who needs to know which emails he has sent and can't see the BCC from his sent items. I've got a powershell script which when runs will pick out the information I am after but keeps all the recipients on one line. What I would like is to have each recipient on their own line. The script I'm using is

 

get-messageTrackingLog -sender start "" -end "" | select Sender, MessageSubject,Recipients | export-csv

 

If I run the above I can get it output each mail that was sent, but the column for the recipients contains multiple email address and is hard to filter. I've tried adding | foreach {$_Recipient} but that only shows the recipient (which is nearly what I am after). Is there a way I can output the Sender, MessageSubject and Recipients so there is a single line for each recipient?

 

Basically the email has been sent to hundreds of people and it would be much easier to work with as individual entries. I'm sure it can be done but I'm not sure how.

Posted (edited)

You will probably need a nested foreach loop. One to loop over the messages and then another to loop over the recipients. I'll try to put something together as a guide for you but don't have exchange so it will need some testing and modification from your side.

 

Edit:

 

$AllMessages = get-messageTrackingLog -sender  start "" -end "" | select Sender, MessageSubject,Recipients 
$Output = @()
foreach ($message in $AllMessages)
{
   foreach ($Recipient in $Message.Recipients) 
   {
       $Output += New-Object -TypeName PSObject -property @{'Sender'=$Message.Sender;'Message Subject'=$Message.MessageSubject;'Recipient'=$Recipient}
   }
}


$output | export-csv 

Edited by halbaradkenafin
  • Thanks 1

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...