Script Repository


Get number of enabled and not expired users in an AD domain without using Adaxes

April 29, 2021
1250

The script returns the number of enabled and not expired user accounts in an AD domain without using Adaxes cmdlets or interfaces. It can be helpful if you want to know how many user accounts will be included in the license count before installing Adaxes.

Note: The computer where you want to run the script must have the Active Directory PowerShell module installed.

Parameters:

  • $domainName - specifies the DNS name of the domain you want to query.
Edit Remove
PowerShell
Import-Module ActiveDirectory

$domainName = "dc.example.com" # TODO: Modify me

$currentDateFileTime = (Get-Date).ToFileTimeUtc()
$users = Get-ADObject -LDAPFilter "(&(sAMAccountType=805306368)(!(userAccountControl:1.2.840.113556.1.4.803:=2))(|(!(accountExpires<=$currentDateFileTime))(accountExpires=0)))" -SearchScope Subtree -Server $domainName
Write-Host "Total number of enabled and not expired user accounts in domain $domainName:" $users.Length

Comments ( 0 )
No results found.
Leave a comment