OK, so this wasn't going to be in the original series I was writing, but an issue came up at work where I needed to quickly find the total number of users in each Storage Group.
Naturally I turned to Powershell for the solution.
Just supply the names of the Storage Groups in a text file, use Powershell to open the text file and for each of the Storage Groups use the Exchange_Mailbox class and filter on the Storage Group name. Use the feature .count to just return the number of users rather than any properties and write to the screen the result.
$StorageGroups = Get-Content c:\Scripts\StorageGroups.txt
foreach ($SG in $StorageGroups){
$Total = (Get-Wmiobject -namespace root\MicrosoftExchangeV2 -class Exchange_Mailbox -computer ExchangeServerName -filter "StorageGroupName = '$SG'").count
Write-Host $SG ":" $Total "users"
}
Which produces something along the lines of:
Storage Group 01 : 152 users
Storage Group 02 : 373 users
Storage Group 03 : 259 users
Storage Group 04 : 220 users
Taking this one step futher you can drill down into the Mailbox Stores with similar code (this time with the names of the Mailbox Stores in a text file) and find how many users on each store:
$MailboxStores = Get-Content c:\Scripts\MailboxStores.txt
foreach ($Store in $MailboxStores){
$Total = (Get-Wmiobject -namespace root\MicrosoftExchangeV2 -class Exchange_Mailbox -computer ExchangeServerName -filter "Storename = '$Store'").count
Write-Host $Store ":" $Total "users"
}
Which gives you the result:
Mailbox Store 01 : 23 users
Mailbox Store 02 : 32 users
Mailbox Store 03 : 41 users
Mailbox Store 04 : 30 users
Mailbox Store 05 : 26 users
Mailbox Store 06 : 39 users
etc.............
No comments:
Post a Comment