Solved

Exchange 2010 Powershell script - Using CSV

Posted on 2014-10-23
7
413 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 2
7 Comments
 
LVL 70

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
Office 365 Training for IT Pros

Learn how to provision tenants, synchronize on-premise Active Directory, implement Single Sign-On, customize Office deployment, and protect your organization with eDiscovery and DLP policies.  Only from Platform Scholar.

 
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 70

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

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

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

After hours on line I found a solution which pointed to the inherited Active Directory permissions . You have to give/allow permissions to the "Exchange trusted subsystem" for the user in the Active Directory...
This article will help to fix the below errors for MS Exchange Server 2013 I. Certificate error "name on the security certificate is invalid or does not match the name of the site" II. Out of Office not working III. Make Internal URLs and Externa…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

707 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