• 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 objects in Active Directory using PowerShell

Counting objects in Active Directory using PowerShell

21/12/2017 by Stephanos 2 Comments

Counting objects in Active Directory using PowerShell

Scenario:

The below basic script will deal only with counting objects in Active Directory using PowerShell. The commands in the script are able to perform the below.

Get instant information about the below:

  • Number of user objects in Active Directory
  • Number of computer objects in Active Directory
  • Number of groups in Active Directory and also separate them by distribution and security groups.

Related Links:

  • Get-ADUser – TechNet – Microsoft
  • Get-ADComputer – TechNet – Microsoft
  • Get-ADGroup – TechNet – Microsoft
  • Counting in Microsoft Exchange using PowerShell

Solution / Script:

$Users = (Get-ADUSer -Filter *).count
$Computers = (Get-ADComputer -Filter *).count
$Groups = (Get-ADGroup -Filter *).count
$Distribution_Groups = (Get-ADGroup -Filter {GroupCategory -eq "Distribution"}).count
$Security_Groups = (Get-ADGroup -Filter {GroupCategory -eq "Security"}).count
Write-Host "Number of users: $Users"
Write-Host "Number of computers: $Computers"
Write-Host "Number of groups: $Groups"
Write-Host "Number of distribution groups: $Distribution_Groups"
Write-Host "Number of security groups: $Security_Groups"

Summary
Counting objects in Active Directory using PowerShell
Article Name
Counting objects in Active Directory using PowerShell
Description
Counting objects in Active Directory using PowerShell. Sample scripts for counting user, computer and group objects in Active Directory. Also separating distribution and security groups. Stephanos Constantinou Blog - PowerShell Scripting
Author
Stephanos
Publisher Name
Stephanos Constantinou Blog
Publisher Logo
Stephanos Constantinou Blog

Filed Under: PowerShell Scripts Tagged With: Comparison Operators, Get-ADComputer, Get-ADGroup, Get-ADUser, PowerShell Operators, Write-Host

Reader Interactions

Comments

  1. George says

    02/09/2020 at 14:32

    thanks Stephanos

    Reply

Trackbacks

  1. Counting in Microsoft Exchange using PowerShell - Stephanos Constantinou Blog says:
    04/05/2018 at 15:55

    […] Counting objects in Active Directory using PowerShell – Stephanos Constantinou Blog says: 27/04/2018 at 12:59 […]

    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