Solved

Exchange 2010 Powershell script - Using CSV

Posted on 2014-10-23
7
384 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
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
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

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

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

A procedure for exporting installed hotfix details of remote computers using powershell
MS Outlook is a world-class email client application that is mainly used for e-communication globally.  In this article, we will discuss the basic idea about MS Outlook, its advanced features, and types of MS Outlook File formats.
In this video, we discuss why the need for additional vertical screen space has become more important in recent years, namely, due to the transition in the marketplace of 4x3 computer screens to 16x9 and 16x10 screens (so-called widescreen format). …
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…

863 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

28 Experts available now in Live!

Get 1:1 Help Now