Here’s a sample on a basic PowerShell script that combines Get-Mailbox, Get-User and Get-MailboxStatistics commands.
The specified objects will be saved into a CSV file.
You can download the script here.
I would be more than happy for any kind of comment or feedback
Feel free to use the script below
#############################################################################
# PS-Merge.ps1
# Description:
# This script combines three commands and sends the output into a CSV file
#
# Jonas Andersson, MCC 2011
# http://www.testlabs.se/blog
# Twitter @jonand82
#############################################################################
#Add Exchange Management Snap-In to recognize Exchange CmdLets in PowerShell
Add-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010 -ErrorAction SilentlyContinue
$Database = @{Name="Database";Expression={ $stats.database }}
$DisplayName = @{Name="DisplayName";Expression={ $stats.DisplayName }}
$StorageLimitStatus = @{Name="StorageLimitStatus";Expression={ $stats.StorageLimitStatus }}
$TotalItemSize = @{Name="MailboxSize";Expression={ $stats.TotalItemSize }}
$Company = @{Name="Company";Expression={ $user.Company}}
$FirstName = @{Name="FirstName";Expression={ $user.FirstName}}
$LastName = @{Name="LastName";Expression={ $user.LastName}}
$LastLogon = @{Name="LastLogon";Expression={ $stats.LastLoggedOnUserAccount}}
$LastLogonTime = @{Name="LastLogonTime";Expression={ $stats.LastLogonTime}}
$Mailboxes = Get-Mailbox -ResultSize Unlimited
$Mailboxes | foreach {
$user = Get-User $_
$stats = Get-MailboxStatistics $_
$_ | select Alias,SamAccountName,$DisplayName,$FirstName,$LastName,$LastLogon,$LastLogonTime,$Company,*SMTP*,$Database,$StorageLimitStatus,$TotalItemSize,RecipientTypeDetails
} | Export-CSV -NoTypeInformation C:\output.csv
Kategorier: Code, Exchange 2010
Taggar: Code, CSV, Exchange, Exchange 2010, PowerShell




Very nice, just what I was looking for.
// Chris
Hi,
Thanks for post! Make easy Outcome from CSV file by using PowerShell commands, I would like to add that you can easily manage and remove columns from a CSV File through PowerShell command. http://blogs.technet.com/b/heyscriptingguy/archive/2011/10/17/easily-remove-columns-from-a-csv-file-by-using-powershell.aspx
Hi there,
Thanks for this script. I have a specific task that your work has helped me out with tremendously. There is one thing I have tried to add and have failed, but it is that I want to include the Manager in the exported CSV but I am trying to get the Manager’s DisplayName instead of the Identity (domain.com/OUName/Manager’sCN). I tried with this:
$ManagerRaw = @{Name=”ManagerRaw”;Expression={$user.Manager}}
$Manager = @{Name=”Manager”;Expression={Get-Mailbox “$($ManagerRaw)”}}
$Manager2 = @{Name=”Manager2″;Expression={$Manager.DisplayName}}
With this though, even if $ManagerRaw is populated, $Manager and $Manager2 are blank. I’m aiming to make $Manager2 show in the CSV as the DisplayName of the Manager. Any thoughts?
Many thanks in advance.
Hi,
Thanks for your feedback and the link you posted!
It’s much appreciated
Rgds
Jonas
Hi Jeremy,
First, thanks for your kind feedback!
It’s always great to see that the posts are helping someone out there
Send me an email at: jonas.andersson@testlabs.se with the details then we can try to work something out
Take care!
Rgds
Jonas
Thanks Jones. It really gave me a good idea.
What if we want to report mailboxes with last logon time older than 90 days?
I modified your script. check it out:
http://refikunver.wordpress.com/2013/01/15/solution-reporting-exchange-20102007-mailboxes-that-has-last-logon-older-than-90-days-error-allowed-maximum-is-524288000/
You’re welcome! Great stuff there!
Keep up the good work