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.by Takuu at 2013-01-31 06:14:17
Using Auto Provision is not an option, as it is already defined to another set of mailbox databases.
Thanks.
This should work for you. My environment is Exchange 2007 with PSv2 but it should work in 2010. Let me know!by ArtB0514 at 2013-01-31 07:05:33$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
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:by Takuu at 2013-01-31 11:31:45$array = @()
Get-MailboxDatabase | foreach {
$array += New-Object PSObject -Property @{
'StorageGroup' = $.name
'MailboxCount' = (Get-Mailbox -Database $).count
}
}
$array
Great suggestion ArtB0514. That does save a lot of typing there.by Optimal at 2013-01-31 12:28:32
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.
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