- Display Name
- Department
- Total Items
- Mailbox Size (MB)
There are two cmdlets needed to access this data:
get-mailboxget-mailboxstatistics
$colMailboxes (information from the get-mailbox cmdlet) and from the $mailboxStats object (information from the get-mailboxstatistics cmdlet). As I looped through the mailboxes, the script creates a string that is then appended to a file.#create the output file
#create object of mailboxes
$colMailboxes = get-mailbox -resultsize unlimited
$strHeaders = "Display Name, Department, Total Items, Mailbox Size (MB)"
write-output $strHeaders
foreach ($objMailbox in $colMailboxes) {
$mailboxStats = get-mailboxstatistics -identity $objMailbox.alias
#if there is an error
if(!$?){
$foreach.movenext()}
else{
$strOutput = $objMailbox.DisplayName + "," + $objMailbox.office + "," + $mailboxStats.ItemCount + "," + $mailboxStats.TotalItemSize.value.toMB()
write-output $strOutput
}
}I saved this as mailbox_size_toCSV.ps1. When running the script the results must be put out to a file.
./mailbox_size_toCSV.ps1 | out-file mbstats.csvThere are probably several things that I could do to improve this script, but it works for me and was pretty easy to put together.
0 comments:
Post a Comment