TL;DR: Why Standard Secure Channel Checks Miss the Root Cause
When a Windows workstation throws "The trust relationship between this workstation and the primary domain failed", fails gpupdate /force over VPN, or locks out a user every 15 minutes after a password change, troubleshooting usually stops at Test-ComputerSecureChannel or nltest /sc_query:<domain>.
Those quick checks are useful, but they leave three big blind spots:
- They don't show which side drifted: After a VM snapshot revert, long offline period, or replication lag,
nltestreturnsNERR_PasswordMismatch(0x5/0x6d9). It won't tell you whether the PC rotated its local LSA secret ahead of AD (LocalAheadOfAD) or AD has a newerpwdLastSet(ADAheadOfLocal). - They skip the
SYSTEM(0x3e7) Kerberos cache: Even when ping and TCP389work, Group Policy and machine auth break ifmsDS-SupportedEncryptionTypesclashes with DC AES policies or if theSYSTEMsession (0x3e7) holds expired orRC4-HMACtickets. - They miss hidden credential overrides: After a password change over VPN or cached logon, stale Credential Manager (
cmdkey) entries,LogonType 11(CachedInteractive) sessions, or lingering SMB connections (MSFT_SmbConnection) can keep replaying the old password in the background.
To pull all of these signals in one pass without RSAT or third-party modules, I wrote Test-ADTrustAndIdentityState.ps1 (a ~1,600-line zero-dependency PowerShell auditor).
1. Machine Trust & LSA Secret Drift ($MACHINE.ACC\CupdTime vs. AD pwdLastSet)
By default, Netlogon rotates a computer's machine password ($MACHINE.ACC) every 30 days. It writes the new secret and a 64-bit FILETIME timestamp to HKLM:\SECURITY\Policy\Secrets\$MACHINE.ACC\CupdTime while updating pwdLastSet on the AD computer object.
Reading CupdTime from PowerShell hits a permissions wall right away. HKLM:\SECURITY\Policy\Secrets is locked to SYSTEM, so even an elevated Administrator gets Access Denied with Get-ItemProperty. Most workarounds spawn psexec -s or edit registry ACLs on HKLM:\SECURITY, which is noisy in EDR logs and risky in production.
Reading it cleanly (SeBackupPrivilege + REG_OPTION_BACKUP_RESTORE): Every elevated Administrator token already has SeBackupPrivilege—it is just disabled by default. Initialize-AdvapiBackupReader compiles a small inline C# P/Invoke helper that enables SeBackupPrivilege on the current process and calls advapi32.dll!RegOpenKeyExW with 0x00000004 (REG_OPTION_BACKUP_RESTORE). That reads the 8-byte CupdTime FILETIME directly without changing a single registry DACL:
# Extract local LSA $MACHINE.ACC\CupdTime and compare against Active Directory pwdLastSet
$Audit = .\Test-ADTrustAndIdentityState.ps1
$Audit.MachineTrust | Select-Object `
SecureChannelHealthy, NltestDcName, LocalCupdTimeUtc, AdPwdLastSetUtc, PasswordDriftState, PasswordDriftHours, SupportedEncryptionNames
Next, Test-MachineTrustState queries pwdLastSet and msDS-SupportedEncryptionTypes via [System.DirectoryServices.DirectorySearcher] and classifies the drift:
InSync: LocalCupdTimeand ADpwdLastSetmatch within replication tolerance.LocalAheadOfAD: The endpoint rotated its local secret, but the change didn't replicate to all DCs (or the PC is talking to a lagging replica).ADAheadOfLocal: AD has a newerpwdLastSetthan the local registry—almost always from a VM snapshot revert, disk restore, or duplicate hostname rejoin.
2. Auditing the SYSTEM (0x3e7) & Interactive Kerberos Caches
Running klist in a normal PowerShell window only shows the signed-in user's tickets. Computer Group Policy, machine 802.1X auth, and Netlogon secure channel traffic all run under NT AUTHORITY\SYSTEM at fixed LogonId 0x3e7.
Get-KerberosTicketState checks both the current user session and klist -lh 0 -li 0x3e7, parses every cached TGT and service ticket, and looks for three common failures:
- Legacy encryption fallbacks (
RC4-HMAC/DES): After Microsoft's Kerberos hardening updates (CVE-2022-37966), DCs that rejectRC4-HMAC(0x4) will break auth if the computer object'smsDS-SupportedEncryptionTypeslacksAES128-CTS-HMAC-SHA1-96(0x8) andAES256-CTS-HMAC-SHA1-96(0x10). The script decodes that bitmask and cross-checks every liveKerbTicket Encryption TypeandSession Key Type. - Expired tickets: Flags tickets past their
End Timethat failed to renew, which usually points to KDC reachability issues or blocked port88traffic. - Correlated System event logs: Pulls recent Netlogon (
3210,5719,5721,5722,5723,5805) and Kerberos (3,4,6,7,14,27) events from the last 24 hours (-EventLookbackHours).
3. Catching Silent Credential Overrides (cmdkey, LogonType 9, and LogonType 11)
Few helpdesk tickets are more frustrating than a workstation that keeps locking out a user (Event ID 4740 on the DC) minutes after a password reset—even after they sign out and back in.
Get-CredentialAndSessionState checks the three places where Windows silently holds onto old credentials:
- Windows Credential Manager (
cmdkey /list): Parses storedDomain PasswordandGenerictargets (termsrv/*,*.corp.example.com, mapped NAS/DFS shares). When a match exists, LSASS silently sends that saved secret over SMB or LDAP instead of the user's fresh Kerberos TGT. - LSASS logon sessions (
Win32_LogonSession&Win32_LoggedOnUser): Lists all active sessions and flagsLogonType 11(CachedInteractive) logons from offline boots before VPN connected,LogonType 9(NewCredentials/runas /netonly) sessions, and any session whoseStartTimeis older than the user's or computer'spwdLastSetin AD. - Active SMB connections (
MSFT_SmbConnection): Shows open SMB mappings, dialect versions, and the credential context bound to each share.
4. Beyond TCP 389: Raw CLDAP UDP Probes and RootDSE Clock Skew
Over a split-tunnel VPN or segmented VLAN, Test-NetConnection -Port 389 only proves a TCP handshake worked. Before Windows ever binds over LDAP or pulls GPOs, the Netlogon locator (DsGetDcName) sends a connectionless CLDAP ping over UDP 389, and Kerberos exchanges tickets over UDP/TCP 88. If a firewall drops UDP 389 or fragments UDP Kerberos packets, domain discovery stalls even while TCP 389 looks fine.
Test-DomainControllerConnectivity tests the exact paths Windows uses against every discovered site DC (falling back to DNS SRV _ldap._tcp.dc._msdcs.<domain> if the trust is too broken for ADSI):
- 1. TCP handshake latency: Measures connect time in milliseconds on ports
389(LDAP),636(LDAPS),3268(Global Catalog), and88(Kerberos). - 2. 44-byte ASN.1 BER CLDAP UDP
389probe (Test-UdpCldapProbe): Sends a minimal 44-byte ASN.1 BER LDAPSearchRequestforobjectClassonRootDSEoverSystem.Net.Sockets.UdpClient. Checking the response andSocketException.SocketErrorCodeseparates a valid0x30ASN.1 reply from an explicitWSAECONNRESET(10054/ICMP Port Unreachable) or a silent firewall drop (TimedOut). - 3. UDP
88Kerberos probe (Test-UdpKerberos88Probe): Checks whether the KDC UDP listener responds or is dropped mid-path. - 4. RootDSE bind & clock skew: Runs an unauthenticated RootDSE bind, parses the DC's
currentTime(yyyyMMddHHmmss.0Z), and calculates exact clock skew in seconds—flagging anything close to the 5-minute (300s) KerberosKRB_AP_ERR_SKEWlimit.
5. Running Test-ADTrustAndIdentityState.ps1 in Production or RMM
The script needs no external modules or RSAT binaries and works on Windows PowerShell 5.1 and PowerShell 7+. Run it interactively to review findings, or pass -Json from an RMM job (running as SYSTEM) to log the output into tickets or custom fields:
# 1. Interactive diagnostic: view prioritized findings and remediation recommendations
$Audit = .\Test-ADTrustAndIdentityState.ps1
$Audit.Findings | Format-Table Severity, Category, Finding, Recommendation -Wrap
# 2. Inspect per-DC TCP/UDP socket latency and Kerberos clock skew
$Audit.DomainControllers.DomainControllers |
Format-Table HostName, SiteName, Tcp389LatencyMs, Udp389CldapStatus, Udp389CldapLatencyMs, RootDseBindLatencyMs, ClockSkewSeconds -AutoSize
# 3. Audit all Domain Controllers across the forest/domain and emit JSON for RMM automation
.\Test-ADTrustAndIdentityState.ps1 -AllDomainControllers -Json
The full script and documentation are in the ActiveDirectory-GPO folder of Windows-Scripts-Tools on GitHub.