Compare mailbox count from seperate databases

This topic contains 0 replies, has 1 voice, and was last updated by Profile photo of Forums Archives Forums Archives 5 years, 5 months ago.

  • Author
    Posts
  • #6509

    by Optimal at 2013-01-30 10:07:58

    I am trying to figure out how many mailboxes are in a mailbox database. The number of mailbox databases is not static, and could be from 1 database to 50. Once I have this info, I want to compare all this data and pick the database with the fewest number of mailboxes.

    Using Auto Provision is not an option, as it is already defined to another set of mailbox databases.

    Thanks.

    by Takuu at 2013-01-31 06:14:17

    This should work for you. My environment is Exchange 2007 with PSv2 but it should work in 2010. Let me know!

    $array = @()
    Get-MailboxDatabase | foreach {
    $storagegroup = New-Object PSObject
    $storagegroup | Add-Member -MemberType NoteProperty -Name StorageGroup -Value $_.name
    $tempVal = Get-Mailbox -Database $_
    $storagegroup | Add-Member -MemberType NoteProperty -Name MailboxCount -Value $tempVal.count
    $array += $storagegroup
    $tempVal = $null
    Remove-Variable storagegroup
    }

    $array | Write-Output

    by ArtB0514 at 2013-01-31 07:05:33

    Just a suggestion... With PS2+, you can save yourself a bunch of typing (and messing with temporary variables) by using the -Property property in New-Object:
    $array = @()
    Get-MailboxDatabase | foreach {
    $array += New-Object PSObject -Property @{
    'StorageGroup' = $_.name
    'MailboxCount' = (Get-Mailbox -Database $_).count
    }
    }
    $array

    by Takuu at 2013-01-31 11:31:45

    Great suggestion ArtB0514. That does save a lot of typing there.
    Maybe I had a typo, but when I tried to do the (Get-Mailbox -Database $_).count I was getting an error. Hence the messy $tempVal I used.

    Thanks again!! I'll be using this format for objects from now on.

    by Optimal at 2013-01-31 12:28:32

    Thank you ArtB and Takuu. The solutions weren't quite what I was looking for, but they allowed me to find what I needed. The $dbs var is user defined. Also, just a note on ArtB's solution: You must add .name to (Get-Mailbox -Database $_).count, otherwise you will have errors. ((Get-Mailbox -Database $_.name).count)

    Thanks again!!!!

    $dbs = ("SERVICE1;SERVICE2;SERVICE3").split(";")

    $array = @()
    $dbs | foreach {
    $array += New-Object PSObject -Property @{
    'StorageGroup' = $_
    'MailboxCount' = (Get-Mailbox -Database $_).count
    }
    }

    $database = ($array | sort MailboxCount –Descending)[0].StorageGroup

    $database

You must be logged in to reply to this topic.