Solved

Exchange 2010 Powershell script - Using CSV

Posted on 2014-10-23
7
404 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 69

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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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 69

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

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.

Question has a verified solution.

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

While rebooting windows server 2003 server , it's showing "active directory rebuilding indices please wait" at startup. It took a little while for this process to complete and once we logged on not all the services were started so another reboot is …
The Windows functions GetTickCount and timeGetTime retrieve the number of milliseconds since the system was started. However, the value is stored in a DWORD, which means that it wraps around to zero every 49.7 days. This article shows how to solve t…
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
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…

730 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