﻿===============================================================================
 SOPHOS ITDR BILLABLE USER COUNT: ON-PREMISES ACTIVE DIRECTORY
 Get-ITDRBillableUsersAD.ps1, version 1.3
===============================================================================

Get-ITDRBillableUsersAD.ps1 estimates how many Sophos ITDR licenses a
customer needs by counting billable users in an on-premises Active Directory
domain. It applies the same criteria Sophos ITDR uses to calculate licensed
usage.

The script is read-only. It does not change anything in Active Directory.


-------------------------------------------------------------------------------
 1. WHEN TO USE THIS SCRIPT
-------------------------------------------------------------------------------

Use this script only for customers that have on-premises Active Directory and
NO Microsoft Entra ID connected to Sophos ITDR.

When a customer has both, Sophos ITDR counts users from Entra ID only, so the
same person is not counted twice. In that case use Get-ITDRBillableUsers.ps1
instead.


-------------------------------------------------------------------------------
 2. LICENSING SUMMARY
-------------------------------------------------------------------------------

Sophos ITDR is licensed per user, for both ITDR Standalone and ITDR as an
XDR/MDR add-on. Servers are not counted, and no multiplier is applied.
Order quantity equals the billable user count.

A user is billable when ALL of the following are true:

  - The account is enabled in the Identity Provider
      (the ACCOUNTDISABLE flag in userAccountControl is not set)

  - The account is not a guest (B2B) user
      (not applicable: Active Directory has no guest account type)

  - The account has logged on within the last 90 days
      (see section 7, "How logon activity is measured")

Accounts that do not meet all criteria are not billable. This includes
disabled accounts, accounts that have never logged on, and accounts with no
logon in the last 90 days.


-------------------------------------------------------------------------------
 3. REQUIREMENTS
-------------------------------------------------------------------------------

  - Windows PowerShell 5.1 or PowerShell 7+ on a domain-joined machine

  - The ActiveDirectory PowerShell module (part of RSAT)

  - A domain account with read access to user objects. A standard domain
    user account is normally enough.


-------------------------------------------------------------------------------
 4. INSTALLATION
-------------------------------------------------------------------------------

On Windows 10 or 11, install the RSAT Active Directory tools from an elevated
PowerShell prompt:

    Add-WindowsCapability -Online -Name Rsat.ActiveDirectory.DS-LDS.Tools~~~~0.0.1.0

On Windows Server:

    Install-WindowsFeature RSAT-AD-PowerShell

If script execution is blocked, allow it for the current session only:

    Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass


-------------------------------------------------------------------------------
 5. RUNNING THE SCRIPT
-------------------------------------------------------------------------------

Basic run against the current domain:

    .\Get-ITDRBillableUsersAD.ps1

Run against a specific domain controller and export per-user detail:

    .\Get-ITDRBillableUsersAD.ps1 -Server dc01.contoso.local -ExportCsv .\contoso-ad.csv

Parameters:

  -Server      (Recommended)
               Domain controller or domain name to query. If omitted, the
               script uses a discovered DC in the current domain.

  -ExportCsv   (Optional)
               Path for a CSV file with one row per user, showing billable
               status and reason.

  -Days        (Optional)
               Logon lookback window in days. Default is 90. Do not change
               this for licensing purposes.


-------------------------------------------------------------------------------
 6. READING THE OUTPUT
-------------------------------------------------------------------------------

The script prints a breakdown by category and the total billable count.
Example:

    Sophos ITDR billable user count (on-prem AD)
    Domain controller: dc01.contoso.local
    Logon cutoff: 2026-08-01 UTC (90 days)

    Category                  Count
    --------                  -----
    Billable                    850
    Disabled                    300
    No logon in 90 days         200
    Never logged on              50

    Total directory users : 1400
    Billable users        : 850

Use the "Billable users" number as the order quantity.

The CSV export includes SamAccountName, UserPrincipalName, DisplayName,
Enabled, LastLogonUtc, Billable and Reason for each user. LastLogonUtc is in
ISO 8601 UTC format, for example 2026-11-09T19:13:55Z. Use the CSV to review
the count with the customer.


-------------------------------------------------------------------------------
 7. HOW LOGON ACTIVITY IS MEASURED
-------------------------------------------------------------------------------

Active Directory stores two last-logon values, and the script uses the later
of the two, read from one domain controller. This is the same method Sophos
ITDR uses.

  lastLogon            Updated on every logon, but stored separately on each
                       domain controller and not replicated.

  lastLogonTimestamp   Replicated to all domain controllers, but only updated
                       about every 14 days.

Because lastLogon differs between domain controllers, running the script
against different DCs can give slightly different results. For the closest
match to Sophos ITDR, use the same domain controller the Sophos ITDR agent
queries. Any domain controller will be accurate to within about 14 days.


-------------------------------------------------------------------------------
 8. THINGS TO KNOW
-------------------------------------------------------------------------------

  - Multiple domains: the script counts one domain per run. Run it once for
    each domain in scope, using -Server to target a DC in each domain, and
    add the billable totals together.

  - Service accounts: account type does not affect the count. An enabled
    service account that has logged on within 90 days is billable.

  - Built-in accounts: the script counts every user object returned by
    Active Directory. Built-in accounts such as Guest and krbtgt are normally
    disabled and so not billable, but the result may be slightly higher than
    the Sophos ITDR count if the agent excludes other system accounts.

  - Point-in-time count: the result reflects the domain at the moment you
    run the script. Sophos ITDR measures usage on an ongoing basis, so the
    in-product count may differ slightly, mostly for users near the 90-day
    boundary.


-------------------------------------------------------------------------------
 9. TROUBLESHOOTING
-------------------------------------------------------------------------------

Symptom:     "ActiveDirectory module not found"
Cause:       RSAT not installed
Resolution:  Run the installation command in section 4.

Symptom:     "Unable to contact the server"
Cause:       DC not reachable, or the machine is not domain-joined
Resolution:  Check network access to the DC, or pass -Server with a
             reachable DC.

Symptom:     Count looks too low
Cause:       lastLogon on the queried DC is stale
Resolution:  Re-run against a different DC, ideally the one the Sophos ITDR
             agent uses.

Symptom:     Count is for the wrong domain
Cause:       Script ran in the current domain
Resolution:  Re-run with -Server pointing at a DC in the target domain.
