We have already reported on useful PowerShell commands for the Active Directory . Today we would like to show you how you can relatively easily count the number of certain AD objects . The fastest and easiest way to perform this AD object count is with a PowerShell command.
First you start a PowerShell console with administrator rights and then execute the following commands.
ActiveDirectory import modules
This loads the necessary PowerShell functions for reading and editing the Active Directory into the PowerShell console. Only then can you issue the following PowerShell commands.
Counting all user AD objects:
(Get-ADUser filter “Name -like ‘*'”). Count
Counting all computer AD objects:
(Get-ADComputer filter “Name -like ‘*'”). Count
We have mapped the entire process including the PowerShell commands once here.
As you can see, the number of AD objects is shown below the command . In our example, there are 737 Active Directory user objects and 901 AD computer objects across the entire domain.
You can of course filter the AD objects even further, for example by adapting the name filter .
(Get-ADComputer filter “Name -like ‘WIN10 *'”). Count
This means that only the AD computer accounts that begin with the name “WIN10” are counted .
But if you would like to have all Active Directory objects listed on which a Windows Server operating system is installed, you should use the following PowerShell command.
(Get-ADComputer filter “OperatingSystem -like ‘* Server *'”). Count
In all of the examples listed, you can simply omit the end with ” ) .count “, but then also the leading ” ( ” at the beginning of the command. Then you will not see the total number of AD objects, but the objects themselves. In this case however, you should then add ” | select DNSHostName ” so that you get a meaningful output
Get-ADUser filter “Name -like ‘*'” | select DNSHostName
Further useful PowerShell commands in connection with the Active Directory can also be found here:
– Find LastLogon (last login) of a user in AD using Get-ADUser
– List AD user accounts that have entered a profile path
– Deactivate user account under Windows 10
– Find out which AD user has never logged in
– List of all XP PCs in the AD Create (Active Directory)