PowerShell script to test Active Directory secure channel against all domain controllers
Windows Server · Active Directory · PowerShell

Test an Active Directory Secure Channel Against Every Domain Controller with PowerShell

A practical, read-only diagnostic guide and downloadable script to discover domain controllers, test the computer secure channel against each one, identify inconsistent results, and produce a report you can use to investigate the problem.

By SmartChoiceLinks Technical GuidesTechnical walkthroughPowerShell 5.1 / 7Approx. 12-minute read
Test-ComputerSecureChannelDomain Controller HealthTroubleshootingCSV + HTML report
Jump to the walkthrough ↓
Safety first: The included script is designed as a read-only diagnostic. It does not repair the secure channel, reset a machine-account password, change DNS settings, or modify Active Directory. Review the script before running it and test it in a suitable environment.

The simple answer

Use PowerShell’s Test-ComputerSecureChannel cmdlet with its -Server parameter to test the local computer’s secure channel against a specific domain controller. To compare results, discover the domain controllers in the computer’s domain and run the test once for each discovered DC.

One secure-channel test against a named DC
Test-ComputerSecureChannel -Server 'dc01.contoso.com' -Verbose

A True result means the secure-channel test succeeded for that computer and selected DC at the time of the test. A False result means the test did not validate successfully. An exception may indicate a discovery, connectivity, permissions, or other operational problem; capture the error rather than treating every exception as a broken machine password.

Key idea — the genius of simplicity: don’t start by repairing anything. First compare the same read-only test across the domain controllers, record the evidence, and then troubleshoot the outlier.

Why test the secure channel against every domain controller?

A computer normally locates a domain controller through Windows domain-controller discovery and site-aware mechanisms. If a machine behaves differently depending on which DC it contacts, a single successful test can hide an inconsistent path or a DC-specific issue.

Testing each discoverable DC can help narrow the investigation. It is not a complete Active Directory health assessment: it does not validate replication, SYSVOL, Group Policy processing, DNS zone health, Kerberos ticket behavior, or every required firewall path.

One DC succeeds, another fails

Investigate DC-specific reachability, DNS answers, site/subnet mapping, time, Netlogon, and replication health.

Every DC fails

Check domain membership, machine account state, DNS client configuration, time synchronization, network access, and relevant event logs.

Discovery fails

Confirm the computer is domain-joined, DNS points to appropriate AD DNS servers, and a DC can be located.

Results change over time

Compare timestamps, network/VPN state, site location, DC availability, and recent machine-account or infrastructure changes.

Prerequisites and compatibility

  • A Windows computer joined to the target Active Directory domain.
  • A user context permitted to run the diagnostic cmdlet; use an elevated PowerShell session if required by your environment.
  • Test-ComputerSecureChannel, available on supported Windows client/server systems with the relevant Windows PowerShell functionality.
  • Domain-controller discovery through the ActiveDirectory PowerShell module, or .NET domain discovery as a fallback.
  • DNS and network connectivity to the domain controllers being tested.
  • For optional TCP checks, permission to test network reachability from the computer to the listed DC ports.
Important: this script is intended to run on a domain-joined Windows computer. It is not a remote fleet-wide scanner. Run it separately on each endpoint you want to diagnose, or adapt it for an approved remote-management workflow.

Download the complete diagnostic script

The script discovers domain controllers, performs a secure-channel test against each one, records DNS resolution, and exports both CSV and HTML reports. Optional TCP checks are available for selected ports.

Test-ADSecureChannelAllDCs.ps1

Read-only · CSV + HTML output · Optional TCP port checks · No automatic repair

What the script does

  1. Attempts DC discovery using the ActiveDirectory module, when installed.
  2. Falls back to .NET domain discovery if the module is unavailable or its query fails.
  3. Resolves each DC hostname to IP addresses.
  4. Runs Test-ComputerSecureChannel -Server <DC FQDN>.
  5. Optionally checks TCP ports 88, 135, 389, 445, 636 and 3268.
  6. Writes timestamped CSV and HTML reports to the selected output directory.

Port checks are basic TCP connection tests, not proof that the corresponding AD service is healthy or that all required AD communication is permitted. The port set is illustrative and may not cover your environment’s requirements.

How to run the PowerShell diagnostic

1

Save the script

Download Test-ADSecureChannelAllDCs.ps1 and save it in a working folder, for example C:\Admin\Scripts.

2

Open PowerShell

Use an approved administrative workstation or the affected domain-joined computer. Follow your organization’s execution policy and script-signing requirements; do not weaken policy globally just to run an unknown script.

3

Run the default read-only test

From the script folder, run:

PowerShell
.\Test-ADSecureChannelAllDCs.ps1
4

Choose an output folder and optional TCP checks

PowerShell
.\Test-ADSecureChannelAllDCs.ps1 `
  -OutputDirectory 'C:\Temp\ADHealth' `
  -TestTcpPorts
5

Review the reports

Open the HTML report for a quick review. Use the CSV report for filtering, comparison, ticket attachments, or further analysis. Treat hostnames, IP addresses, and error messages as internal infrastructure data.

Sample output: what good and bad results look like

The following is illustrative sample data, not output from a real domain. Your results will depend on your domain, endpoint, network, and DC configuration.

Example console summary
Discovering domain controllers for WS-CLIENT-07 ...
Testing dc01.contoso.com ...
Testing dc02.contoso.com ...
Testing dc03.contoso.com ...

1 of 3 domain controller tests did not return True.
Investigate the affected DCs and network path.

CSV : C:\Temp\ADSecureChannelReport\WS-CLIENT-07-ADSecureChannel-20261126-103000.csv
HTML: C:\Temp\ADSecureChannelReport\WS-CLIENT-07-ADSecureChannel-20261126-103000.html

Read-only diagnostic: no repair or AD changes were performed.
ComputerDomain controllerDNSSecure channelInitial interpretation
WS-CLIENT-07dc01.contoso.comResolvedTrueTest succeeded against this DC.
WS-CLIENT-07dc02.contoso.comResolvedTrueTest succeeded against this DC.
WS-CLIENT-07dc03.contoso.comResolvedFalseInvestigate this DC and the path to it.

Do not conclude from one failed row that the machine account is definitely broken. Confirm the result, inspect the captured exception (if any), compare DNS and connectivity, and check DC health before considering a repair.

Troubleshooting: common results and next checks

1. Test-ComputerSecureChannel returns False for one DC

Repeat the test against that DC and a known-good DC. Check whether the endpoint can resolve and reach the failing DC, whether the DC is healthy, and whether the endpoint is using the expected DNS servers and AD site. Review Netlogon and System event logs on the endpoint and DC.

Repeat one test with verbose output
Test-ComputerSecureChannel -Server 'dc03.contoso.com' -Verbose

2. The cmdlet throws an exception

Capture the full error record. Check name resolution, route/VPN state, firewall rules, DC availability, and whether the selected hostname is a valid DC FQDN. An exception is not the same thing as a confirmed secure-channel password mismatch.

3. Domain controller discovery fails

Check domain membership and DNS client configuration. From the endpoint, you can also run:

DC locator check
nltest /dsgetdc:contoso.com

Replace contoso.com with your actual AD DNS domain. A DC locator failure points to a discovery/connectivity investigation before you attempt a secure-channel repair.

4. DNS resolves, but the secure-channel test fails

DNS resolution only proves that a name resolved to an address. It does not prove that Kerberos, LDAP, SMB, RPC, Netlogon, time synchronization, or replication are healthy. Check the ports and protocols required by your topology and security policy.

5. All DC tests fail

Validate that the endpoint is domain joined and has the correct DNS client settings. Check time synchronization, VPN/network reachability, machine-account status, Netlogon service state, and relevant event logs. Compare with another known-good domain-joined endpoint on the same network.

6. One site or subnet behaves differently

Review AD Sites and Services subnet mapping, site-link configuration, DNS SRV records, and the DCs advertised to that client location. A site mapping issue can send clients to unexpected DCs.

Should you repair the secure channel?

Only after you have collected evidence and identified the likely cause. Repair operations can change the machine-account password relationship and should be performed under your organization’s change-control process, with appropriate privileges and a recovery plan.

Do not blindly run: Test-ComputerSecureChannel -Repair or reset the computer account just because one DC test failed. First confirm the scope of the failure, verify DC health and connectivity, and coordinate with the AD team.

Microsoft documents Test-ComputerSecureChannel as a cmdlet for testing and, when explicitly requested, repairing the secure channel. Read the official documentation and your organization’s operational procedures before using repair options.

Microsoft Learn: Test-ComputerSecureChannel

What this diagnostic does not prove

  • It does not prove Active Directory replication is healthy. Use appropriate replication diagnostics such as repadmin and review the results in context.
  • It does not validate SYSVOL or NETLOGON share availability, Group Policy processing, or DFSR health.
  • It does not guarantee that every required AD port is open. The optional TCP checks are a limited reachability sample.
  • It does not test every computer in the domain. It tests the computer on which the script is run.
  • It does not establish that a DC is globally healthy merely because one secure-channel test returns True.

Frequently asked questions

How do I test an Active Directory secure channel against a specific domain controller?

Run Test-ComputerSecureChannel -Server 'dc01.contoso.com' -Verbose on the domain-joined computer. Replace the example hostname with the DC FQDN you want to test.

Can I test the secure channel against all domain controllers with PowerShell?

Yes. Discover the domain controllers in the computer’s domain and run Test-ComputerSecureChannel -Server for each one. The downloadable script in this guide automates that read-only comparison and exports reports.

Does Test-ComputerSecureChannel repair the computer account automatically?

No. A normal test checks the secure channel. Repair is a separate, explicit operation. The included script does not use the repair option.

Why does the secure-channel test succeed against one DC but fail against another?

Possible causes include DC-specific connectivity, DNS, site selection, DC health, time, Netlogon, or replication issues. A single inconsistent result is a reason to investigate the endpoint-to-DC path; it is not by itself proof of a broken machine-account password.

Do I need the ActiveDirectory PowerShell module?

The script prefers the ActiveDirectory module for DC discovery. If it is unavailable or its query fails, it attempts .NET domain discovery. The computer must still be domain joined and able to locate a domain controller.

Which ports should I test between a client and a domain controller?

Required ports depend on the Windows versions, services, topology, and operations in use. The optional script checks a small illustrative subset only. Use Microsoft’s current port requirements and your network team’s approved rules for a complete assessment.

Can I run this script remotely against every computer in my domain?

Not as written. It runs locally on one computer. A remote deployment would need an approved management mechanism, appropriate credentials, error handling, and careful control of concurrency and output collection.

Need experienced infrastructure support?

Make infrastructure problems simpler to diagnose.

SmartChoiceLinks also offers Advanced Tech Solutions & AI Services for organizations that need practical Windows Server, Active Directory, VMware, PowerShell automation, infrastructure troubleshooting, and technical problem-solving support.

For a service discussion, describe your environment, symptoms, urgency, and the outcome you need.

Explore Global IT Services →

Share this technical guide

If this diagnostic helped you, share it with your IT team or infrastructure community.

SmartChoiceLinks · Practical tools. Clear answers.

This article is provided for educational and troubleshooting purposes. Validate scripts in a test environment and follow your organization’s security, change-management, and operational policies. Windows/Active Directory behavior and supported configurations may vary by version and environment.

Back to top ↑


Leave a Reply

Your email address will not be published. Required fields are marked *