We use cookies to improve your experience.
By your continued use of this site you accept such use.
For more details please see our privacy policy and cookies policy.

Script Repository

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

October 12, 2023 Views: 1998

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 2
avatar
Eric Schewe Oct 12, 2023
There is a small typo in the last line of this script:

Write-Host "Total number of enabled and not expired user accounts in domain $domainName:" $users.Length

Should be:

Write-Host "Total number of enabled and not expired user accounts in domain $($domainName):" $users.Length

Otherwise it errors out on execution in PowerShell v5.x
avatar
Support Oct 12, 2023
Hello Eric,

Thank you for pointing out the issue. We updated the script accordingly.
Leave a comment
Loading...

Got questions?

Support Questions & Answers