Count Mailboxes in Organization Unit
Introduction
This script will count Mailboxes in Organization Unit excluding its Child Organization Unit.
Scenarios
This script is to help Exchange Administrator to count Mailboxes in Organization Unit excluding its Child Organization Unit via PowerShell.
Script
This script contains one advanced function Count-OSCMailboxInOU, you can use this script in the following ways:
Step1: Run the script in the Exchange Management Shell, type the one command: Import-Module <Script Path> at the prompt.
For example, type Import-Module C:\Script\CountMailboxInOU.psm1
Here are some code snippets for your references.
if($checkou){
#Count mailboxes
$Count = $null
$Count = Get-User -ResultSize Unlimited | Where{$_.OrganizationalUnit -like "*$ou" -and $_.RecipientType -eq "UserMailbox"} | Group-Object RecipientType | Select Count -ExpandProperty Count
if($Count -eq $null){
$Count = 0
}
Write-Host "Organization Unit $ou has $Count Mailboxes."
}
if($checkou){
#Count mailboxes
$Count = $null
$Count = Get-User -ResultSize Unlimited | Where{$_.OrganizationalUnit -like "*$ou" -and $_.RecipientType -eq "UserMailbox"} | Group-Object RecipientType | Select Count -ExpandProperty Count
if($Count -eq $null){
$Count = 0
}
Write-Host "Organization Unit $ou has $Count Mailboxes."
}
Examples
Example 1: Count the Mailboxes in Organization Unit OU1 excluding its child OU.
Command: Count-OSCMailboxInOU -OrganizationUnit "OU1"
Screenshot:
Prerequisite
Exchange 2010 and above Exchange Version
English Version only
PowerShell 2.0
Microsoft All-In-One Script Framework is an automation script sample library for IT Professionals. The key value that All-In-One Script Framework is trying to deliver is Scenario-Focused Script Samples driven by IT Pros' real-world pains and needs. The team is monitoring all TechNet forums, IT Pros' support calls to Microsoft, and script requests submitted to TechNet Script Repository. We collect frequently asked IT scenarios, and create script samples to automate the tasks and save some time for IT Pros. The team of All-In-One Script Framework sincerely hope that these customer-driven automation script samples can help our IT community in this script-centric move.