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.
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
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
Thank you for pointing out the issue. We updated the script accordingly.