Domain Secure Channel Validator

Proactive IT Automation Solutions

Streamlining Active Directory Trust Management

Managing domain trust across a large environment can be a major bottleneck for any Systems Engineer. If you’ve ever dealt with “broken secure channel” errors affecting group policy updates or authentication, you know how time-consuming manual checks can be.

I’ve developed an automated PowerShell utility that streamlines this process. The script performs a two-stage audit:

  • Discovery: Identifies all machines within your specified OUs.
  • Validation: Remotely validates the health of the secure channel for each host and exports a consolidated report.

Ready to automate your AD audits?

— Part 1: Export Computer List —

Import-Module ActiveDirectory

$OUs = @(
“OU=Computers,OU=Department1,DC=domain,DC=com”,
“OU=Computers,OU=Department2,DC=domain,DC=com”
)

$computers = foreach ($OU in $OUs) {
Get-ADComputer -Filter * -SearchBase $OU -Property Name | Select-Object -ExpandProperty Name
}

$computers | Out-File -FilePath “C:\computers.txt”

— Part 2: Validate Secure Channel Status —

$targetDomain = “domain.com”
$computersFile = “C:\computers.txt”
$outputCsv = “C:\domain_trust_results.csv”

if (-not (Test-Path $computersFile)) {
Write-Host “Computer list file not found: $computersFile” -ForegroundColor Red
exit
}

$results = foreach ($computer in Get-Content $computersFile) {
$computer = $computer.Trim()
Write-Host “Checking trust for: $computer” -ForegroundColor Cyan$status = if (Test-Connection -ComputerName $computer -Count 1 -Quiet) { try { $nltest = nltest /sc_query:$targetDomain /server:$computer if ($nltest -match "NERR_Success") { "Valid Trust" } else { "Broken Trust" } } catch { "Error: $($_.Exception.Message)" } } else { "Not Reachable" } [PSCustomObject]@{ ComputerName = $computer Status = $status }

}

$results | Export-Csv -Path $outputCsv -NoTypeInformation
Write-Host “Results exported to $outputCsv” -ForegroundColor Green


Leave a Reply

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