?
Solved

Exchange 2010 Powershell script - Using CSV

Posted on 2014-10-23
7
Medium Priority
?
440 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 2000 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
Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

 
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

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

Question has a verified solution.

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

This article shows how to use a free utility called 'Parkdale' to easily test the performance and benchmark any Hard Drive(s) installed in your computer. We also look at RAM Disks and their speed comparisons.
Sometimes clients can lose connectivity with the Lotus Notes Domino Server, but there's not always an obvious answer as to why it happens.   Read this article to follow one of the first experiences I had with Lotus Notes on a client's machine, my…
The Task Scheduler is a powerful tool that is built into Windows. It allows you to schedule tasks (actions) on a recurring basis, such as hourly, daily, weekly, monthly, at log on, at startup, on idle, etc. This video Micro Tutorial is a brief intro…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
Suggested Courses

765 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