Exchange 2010, PowerShell

Selected PowerShell commands, output to CSV file

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

Tagged , , , ,