Solved

Exchange 2010 Powershell script - Using CSV

Posted on 2014-10-23
7
376 Views
Last Modified: 2014-10-23
Trying to build a script to get some statistical information on all of my mailboxes on a single server.   I have got the basics down, just trying to get things to output the way I want.  I have limited (but increasingly more and more) experience in power shell.

I am trying to get an idea of the total number of items in a users mailbox over a given time period.  We are looking for a separate txt file for each mailbox.  

I can get the data out just fine if I manually do each mailbox.  So, I am attempting to dump my mailboxes to a CSV and then use that file to pull in the needed variables:

get-messagetrackinglog -ResultSize Unlimited -Recipient user@domain.com $line -Start "09/22/2014 12:00:00 AM" -End "10/22/2014 11:59:00 PM" | select timestamp, messageid, messagesubject, sender, {$_.recipients}, totalbytes, recipientcount | export-csv c:\shoretemp\user-receive-all.csv

Open in new window


So, here is my overall script

Get-Mailbox -server cas.packetfusion.com |Select-Object PrimarySMTPAddress |Out-file c:\report\mailboxes.csv
$csvFile = "C:\report\mailbox.csv"
$csv = Import-csv $csvFile
foreach ($line in $csv) {
	get-messagetrackinglog -ResultSize Unlimited -Recipient $line -Start "09/22/2014 12:00:00 AM" -End "10/22/2014 11:59:00 PM" | select timestamp, messageid, messagesubject, sender, {$_.recipients}, totalbytes, recipientcount | export-csv c:\shoretemp\user-receive-all".csv
		}

Open in new window


Tryng to figure out how I can pipe some inforamtion into the fielname to make it unique .  I can always add another column in the orginal csv file, I just need to know how to pipe the column into the filename (assuming I can do it via the foreach ($row in $csv)
0
Comment
Question by:JamesonJendreas
  • 5
  • 2
7 Comments
 
LVL 68

Accepted Solution

by:
Qlemo earned 500 total points
ID: 40399600
You should not export to csv just to read it back in in the same script. Except if you need the export anyway. Just pass the objects down the pipe for further processing.

You should restrict the output of the message tracking log to one event, e.g. RECEIVE, because each mail causes several entries in the log (receive, resolve, deliver, ...).
[DateTime] $StartDate = "09/22/2014 12:00:00 AM"
[DateTime] $EndDate   = $startDate.AddDays(2).AddSeconds(-1)

Get-Mailbox -server cas.packetfusion.com |
  Select-Object -Expand PrimarySMTPAddress | % {
    Get-MessageTrackingLog -ResultSize Unlimited -Recipient $_ -Start $StartDate -End $EndDate -EventID Receive |
      select timestamp, messageid, messagesubject, sender, {$_.recipients}, totalbytes, recipientcount |
      export-csv "c:\shoretemp\user-receive-all-$_.csv"
  }

Open in new window

0
 
LVL 1

Author Comment

by:JamesonJendreas
ID: 40399615
Awesome - let me give it a run and see how it goes.
0
 
LVL 1

Author Comment

by:JamesonJendreas
ID: 40399628
Looks like it's now returning an error regarding running concurrent pipelines
0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
LVL 1

Author Comment

by:JamesonJendreas
ID: 40399679
I beleive i could get around concurrent piping (Add-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010 command), but I wonder what kind of load that would put on the server.
0
 
LVL 1

Author Closing Comment

by:JamesonJendreas
ID: 40399715
Worked once I got around concurrent piping
0
 
LVL 68

Expert Comment

by:Qlemo
ID: 40399730
Don't care about the performance. It is still one command at a time running, but the intermediate results can be just past thru the pipe and destroyed if not needed as soon as possible. So performance will even be much better than if you create files for intermediate results.
0
 
LVL 1

Author Comment

by:JamesonJendreas
ID: 40399792
Yeah - it works just fine and runs quickly and doesn't eat up resources.  I'm sure it helps that my exchange system is pretty small in the grand scheme of things.
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

Utilizing an array to gracefully append to a list of EmailAddresses
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.
In this video we show how to create a mailbox database in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.: First we need to log into the Exchange Admin Center. Navigate to the Servers >> Data…
The video tutorial explains the basics of the Exchange server Database Availability groups. The components of this video include: 1. Automatic Failover 2. Failover Clustering 3. Active Manager

746 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

11 Experts available now in Live!

Get 1:1 Help Now