Announcement

Collapse
No announcement yet.

Powershell script for Exchange Mailbox report

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Powershell script for Exchange Mailbox report

    I'm trying to generate a Powershell report for Exchange 2007. Your help is greatly appreciated.

    Here is what I have.
    $Mbxs = Get-Mailbox -ResultSize Unlimited
    $(Foreach ($MB in $Mbxs){
    $MailboxStat = $MB | Get-MailboxStatistics
    New-Object PSObject -Property @{
    Employee = $MB.DisplayName
    UseDefault = $MB.UseDatabaseQuotaDefaults
    TotalItems = $MailboxStat.ItemCount
    TotalSizeMB = $MailboxStat.TotalItemSize.Value.ToMB()
    Inbox = ($MB | Get-MailboxFolderStatistics -FolderScope Inbox).ItemsInFolder
    SentItems = ($MB | Get-MailboxFolderStatistics -FolderScope SentItems).ItemsInFolder
    DeletedItems = ($MB | Get-MailboxFolderStatistics -FolderScope DeletedItems).ItemsInFolder
    DeletedSizeMB = $MailboxStat.TotalDeletedItemSize.Value.ToMB()
    }
    }) | Export-Csv -Path "C:\PS_Rpts\MailboxSize-$(Get-Date -f dd-MM-yyy).csv" -NoTypeInformation

    I'm trying to get these columns only:

    Employee Name
    Inbox count(including sub-folders), Inbox size (including sub-folders)
    sent Items count(including sub-folders), Sent Items size (including sub-folders)
    Deleted Items count(including sub-folders), deleted Items size (including sub-folders)
    Written to a CSV file c:\PS_Rpts\Mailbox_Stats-(current date)

  • #2
    I think this should do it for you:
    Code:
    $Mbxs = Get-Mailbox -ResultSize Unlimited
    
    $(Foreach ($MB in $Mbxs){
        $MBinbox = $MB | Get-MailboxFolderStatistics -FolderScope Inbox
        If($MBinbox.count -gt 1){
            $InboxCount = $MBinbox[0].ItemsInFolderAndSubfolders
            $InboxSizeMB = $MBinbox[0].FolderAndSubfolderSize.ToMB()
            } Else {
            $InboxCount = $MBinbox.ItemsInFolderAndSubfolders
            $InboxSizeMB = $MBinbox.FolderAndSubfolderSize.ToMB()
        }
        $MBsent = $MB | Get-MailboxFolderStatistics -FolderScope SentItems
        If($MBsent.count -gt 1){
            $SentCount = $MBsent[0].ItemsInFolderAndSubfolders
            $SentSizeMB = $MBSent[0].FolderAndSubfolderSize.ToMB()
            } Else {
            $SentCount = $MBsent.ItemsInFolderAndSubfolders
            $sentSizeMB = $MBsent.FolderAndSubfolderSize.ToMB()
        }
        $MBdeleted = $MB | Get-MailboxFolderStatistics -FolderScope DeletedItems
        If($MBdeleted.count -gt 1){
            $DeletedCount = $MBDeleted[0].ItemsInFolderAndSubfolders
            $DeletedSizeMB = $MBdeleted[0].FolderAndSubfolderSize.ToMB()
            } Else {
            $DeletedCount = $MBDeleted.ItemsInFolderAndSubfolders
            $DeletedSizeMB = $MBdeleted.FolderAndSubfolderSize.ToMB()
        }
        New-Object PSObject -Property @{
            Employee = $MB.DisplayName
            Inbox = $inboxCount
            InboxSizeMB = $InboxSizeMB
            SentItems = $SentCount
            SentItemSizeMB = $SentSizeMB
            DeletedItems = $DeletedCount
            DeletedSizeMB = $DeletedSizeMB
        }
    }) | Select Employee,Inbox*,Sent*,Delet* | Export-Csv -Path "C:\MailboxSize-$(Get-Date -f dd-MM-yyy).csv" -NoTypeInformation
    Regards,
    Jeremy

    Network Consultant/Engineer
    Baltimore - Washington area and beyond
    www.gma-cpa.com

    Comment

    Working...
    X