Skip to content

Instantly share code, notes, and snippets.

@tanfwc
Last active December 17, 2024 04:18
Show Gist options
  • Save tanfwc/e55e67e18079765cb630d9dc7b436681 to your computer and use it in GitHub Desktop.
Save tanfwc/e55e67e18079765cb630d9dc7b436681 to your computer and use it in GitHub Desktop.
MSP - Quick Domain Controller Checks
#
# Invoke-Expression (New-Object Net.WebClient).DownloadString('https://gist.githubusercontent.com/tanfwc/e55e67e18079765cb630d9dc7b436681/raw/6a61bd2f4d3cb8ccbe7a05c090d59cf4f3490cfe/qiuck_ad_check.ps1')
# Function to test network connectivity to the Domain Controller
function Test-NetworkConnectivity {
Write-Host "`nTesting Network Connectivity..." -ForegroundColor Cyan
$DomainName = $env:USERDNSDOMAIN
if (-not $DomainName) {
Write-Host "This computer is NOT joined to a domain." -ForegroundColor Red
return
}
$DomainController = (nltest /dsgetdc:$DomainName | Select-String "DC:").ToString().Split(":")[1].Trim()
if ($DomainController) {
Write-Host "Domain Controller detected: $DomainController" -ForegroundColor Green
$PingResult = Test-Connection -ComputerName $DomainController -Count 2 -Quiet
if ($PingResult) {
Write-Host "Network connectivity to Domain Controller is OK." -ForegroundColor Green
} else {
Write-Host "Network connectivity to Domain Controller FAILED." -ForegroundColor Red
}
} else {
Write-Host "Could not detect a Domain Controller." -ForegroundColor Red
}
}
# Function to check computer domain join status
function Test-DomainJoinStatus {
Write-Host "`nChecking Domain Join Status..." -ForegroundColor Cyan
$DomainName = $env:USERDNSDOMAIN
if ($DomainName) {
Write-Host "This computer is joined to the domain: $DomainName" -ForegroundColor Green
} else {
Write-Host "This computer is NOT joined to any domain." -ForegroundColor Red
}
}
# Function to test Kerberos Authentication
function Test-Kerberos {
Write-Host "`nChecking Kerberos Authentication..." -ForegroundColor Cyan
try {
klist.exe | Out-Null
Write-Host "Kerberos tickets detected. Authentication is working." -ForegroundColor Green
} catch {
Write-Host "Kerberos ticket check FAILED. Ensure the system time is synchronized." -ForegroundColor Red
}
}
# Function to check system time synchronization
function Test-TimeSync {
Write-Host "`nChecking System Time Synchronization..." -ForegroundColor Cyan
$W32Time = w32tm /query /status | Select-String "Source"
if ($W32Time) {
Write-Host "Time Source: $W32Time" -ForegroundColor Green
} else {
Write-Host "Time synchronization check FAILED. Check NTP settings." -ForegroundColor Red
}
}
# Main Execution
Write-Host "=== Active Directory Connectivity Health Check ===`n" -ForegroundColor Yellow
Test-DomainJoinStatus
Test-NetworkConnectivity
Test-Kerberos
Test-TimeSync
Write-Host "`n=== Check Completed ===" -ForegroundColor Yellow
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment