• Skip to primary navigation
  • Skip to main content
  • Skip to footer

Stephanos Constantinou Blog

PowerShell Scripting

  • Home
  • Blogs
    • PowerShell Tutorials
    • PowerShell Scripts
    • PowerShell Modules
      • Modules Cmdlets
    • Software Reviews
  • About
  • Contact
You are here: Home / PowerShell Scripts / Counting in Microsoft Exchange using PowerShell

Counting in Microsoft Exchange using PowerShell

21/12/2017 by Stephanos 1 Comment

Counting in Microsoft Exchange using PowerShell

Scenario:

Counting in Microsoft Exchange using PowerShell.

Get the number of the below in Microsoft Exchange:

  • Number of mailboxes in Microsoft Exchange and separate them by UserMailbox, SharedMailbox and RoomMailbox
  • Number of contacts in Microsoft Exchange and separate them by contact and mail contacts
  • Number of groups in Microsoft Exchange and separate them by distribution and security groups.
Connect on Microsoft Exchange OnPremise:
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://exchange.domain.com/PowerShell/ -Authentication Kerberos
Import-PSSession $Session
Connect on Microsoft Exchange Online:
$Credentials = $host.ui.PromptForCredential("Need credentials", "Provide Cloud User Admin Password Name Surname.", "name@domain.com", "UserName")
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://ps.outlook.com/powershell/ -Credential $Credentials -Authentication Basic -AllowRedirection
Import-PSSession $Session
Options for RecipientTypeDetails in Get-Mailbox:
  • DiscoveryMailbox
  • EquipmentMailbox
  • GroupMailbox
  • LegacyMailbox
  • LinkedMailbox
  • LinkedRoomMailbox
  • RoomMailbox
  • SchedulingMailbox
  • SharedMailbox
  • TeamMailbox
  • UserMailbox
Options for RecipientTypeDetails in Get-Contact:
  • Contact
  • MailContact
  • MailForestContact
Options for RecipientTypeDetails in Get-DistributionGroup:
  • MailNonUniversalGroup
  • MailUniversalDistributionGroup
  • MailUniversalSecurityGroup
  • RoomList

Related Links:

  • PowerShell Tutorials
  • PowerShell Scripts
  • Get-Mailbox – TechNet – Microsoft
  • Get-Contact – TechNet – Microsoft
  • Get-MailContact – TechNet – Microsoft
  • Get-DistributionGroup – TechNet – Microsoft
  • Import-PSSession – Microsoft Docs
  • New-PSSession – Microsoft Docs
  • Write-Host – Microsoft Docs

Solution / Script:

$Mailboxes = (Get-Mailbox -ResultSize Unlimited).count
$UserMailboxes = (Get-Mailbox -ResultSize Unlimited -RecipientTypeDetails UserMailbox).count
$RoomMailboxes = (Get-Mailbox -ResultSize Unlimited -RecipientTypeDetails RoomMailbox).count
$SharedMailboxes = (Get-Mailbox -ResultSize Unlimited -RecipientTypeDetails SharedMailbox).count
$Contacts = (Get-Contact -ResultSize Unlimited).count
$MailContacts = (Get-Contact -ResultSize Unlimited -RecipientTypeDetails MailContact).count ###or you can use (Get-MailContact -ResultSize Unlimited).count
$Groups = (Get-DistributionGroup -ResultSize Unlimited).count
$DistributionGroups = (Get-DistributionGroup -ResultSize Unlimited -RecipientTypeDetails MailUniversalDistributionGroup).count
$SecurityGroups = (Get-DistributionGroup -ResultSize Unlimited -RecipientTypeDetails MailUniversalSecurityGroup).count
Write-Host "Number of mailboxes: $Mailboxes"
Write-Host "Number of user mailboxes: $UserMailboxes"
Write-Host "Number of room mailboxes: $RoomMailboxes"
Write-Host "Number of shared mailboxes: $SharedMailboxes"
Write-Host "Number of contacts: $Contacts"
Write-Host "Number of mail contacts: $MailContacts"
Write-Host "Number of groups: $Groups"
Write-Host "Number of distribution groups: $DistributionGroups"
Write-Host "Number of security groups: $SecurityGroups"

Summary
Counting in Microsoft Exchange using PowerShell
Article Name
Counting in Microsoft Exchange using PowerShell
Description
Counting in Microsoft Exchange using PowerShell. Scripts that you can count user mailboxes, shared mailboxes, room mailboxes, contacts mail contacts, distribution groups, and security groups in Microsoft Exchange. Stephanos Constantinou Blog - PowerShell Scripting
Author
Stephanos
Publisher Name
Stephanos Constantinou Blog
Publisher Logo
Stephanos Constantinou Blog

Filed Under: PowerShell Scripts Tagged With: Get-Contact, Get-DistributionGroup, Get-Mailbox, Get-MailContact, Import-PSSession, Microsoft Office 365, New-PSSession, Write-Host

Reader Interactions

Trackbacks

  1. Counting objects in Active Directory using PowerShell - Stephanos Constantinou Blog says:
    27/04/2018 at 12:59

    […] Counting in Microsoft Exchange using PowerShell […]

    Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Footer

Recent Posts

  • ICS Cube Product Review 26/04/2019
  • PowerShell Module SysInfo v1.2.0 15/03/2019
  • PowerShell Module SysInfo v1.1.2 13/11/2018
  • PowerShell Module SysInfo 24/10/2018
  • Get-VoltageProbe 24/10/2018
  • Get-VideoController 24/10/2018
  • Get-USBController 24/10/2018
  • Get-TrackPoint 24/10/2018
  • Get-TrackBall 24/10/2018
  • Get-TouchScreen 24/10/2018
Planet PowerShell

Categories

  • Modules Cmdlets (57)
  • PowerShell Modules (5)
  • PowerShell Scripts (38)
  • PowerShell Tutorials (35)
  • Software Reviews (2)

Archives

  • April 2019 (1)
  • March 2019 (1)
  • November 2018 (1)
  • October 2018 (56)
  • September 2018 (13)
  • August 2018 (9)
  • July 2018 (6)
  • June 2018 (8)
  • May 2018 (7)
  • April 2018 (9)
  • March 2018 (4)
  • February 2018 (6)
  • January 2018 (12)
  • December 2017 (4)
Top 10 PowerShell 2018

Blogroll

  • Planet PowerShell
  • Reddit – PowerShell
  • PowerShell Magazine
  • PowerShell.org
  • PowerShell Team Blog
  • Hey, Scripting Guy! Blog
  • Mike F Robbins
  • PowerShell Explained with Kevin Marquette
  • Mike Kanakos – Network Admin
  • The Lonely Administrator
  • AskME4Tech
PowerShell Blogs Sysadmin Blogs Banners for Top 20 Programming Blogs

© 2023 · Stephanos Constantinou Blog

  • Home
  • Blogs
  • About
  • Contact