PowerShell, Scripts

PowerShell – Export Exchange Mailbox Name, Item Count and Size to CSV

Below is a PowerShell script I wrote to connect to Exchange through Remote PowerShell, import a list of users from a CSV file, grab the Display Name, Total Item Count and Total Size in GB for each user mailbox and export back to CSV.

You will need to modify the $conuri variable to connect to your Exchange server using the full FQDN, for example, (http://mailserver.scottellis.com/PowerShell).

You can download the full script here: Script


#Written by Scott Ellis
#April 2016

#Gets User Credential for Remote PowerShell Session and sets variable
$creds = Get-Credential

#Sets Variable for Mail Server Connection URI
$conuri = "http://FQDNMAILSERVER/PowerShell/"

#Sets Variable for CSV file listing users to be imported
$mailboxusers = "C:\Temp\list_of_users.csv"

#Sets Output file location
$outputfile = "C:\temp\list_of_users_mailbox details.csv"

#Starts a new Remote PowerShell session to Exchange Server
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri $conuri -Credential $creds

#Waits for connection to Exchange Server to complete
Start-Sleep -s 10

#Opens Remote PowerShell session to Exchange Server
Import-PSSession $Session

#Waits for Remote PowerShell session to Exchange Server to open
Start-Sleep -s 30

#Imports list of users in CSV file, gets mailbox stats, including DisplayName, Total Item Count and Total Mailbox Size in GB, sorts by DisplayName and Exports to CSV file
Import-Csv $mailboxusers |foreach {Get-MailboxStatistics -Identity $_.alias} |select displayname,itemcount,totalitemsize | sort-object DisplayName | export-csv $outputfile

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s