Friday, 14 July 2023

PowerShell : Remote Health check on a Domain Controller Using PowerShell

 PowerShell : Remote  Health check on a Domain Controller Using PowerShell




# Import the Acitve Directory Module

Import-Module ActiveDirectory

 

# Define the Domain Controller Name

$domainController = "<DomainControllerName>"

 

# Check if the Domain Controller is reachable

 

if (Test-Connection -ComputerName $domainController -Count 1 -Quiet) {

       Write-Host "Domain Controller '$domainController' is reachable."

 

# Check if the Domain Controller is responding to LDAP queries

       try {

              $ldap = [System.DirectoryServices.DirectoryEntry]::Create("LDAP://$domainController")

              $ldap.NativeObject | Out-Null

              Write-Host "LDAP Connectivity to Domain Controller '$domainController' is successful."

           }

       catch {

              Write-Host "LDAP connectivity to Domain Controller '$domainController' faied."

             }

# Check the replication status

       $replicationResult = Get-ADReplicationPartnerMetadata -Target $domainController -Scope Domain | select-object Partner, LastReplicationSucess

       write-Host "Replication status for Domain Controller '$domainController':"

       $replicationResult

# Check the SYSVOL replication status

       $sysvolResult = Get-ADReplicationFailure -Target $domainController -Scope Domain | Select-Object Partner, FailureType, FirstFailureTime, FailureCount

       Write-Host "SYSVOL replication status for Domain Controller '$domainController':"

       $sysvolResult

}

else

{

       Write-Host "Domain Controller '$domainController' is not reachable."

}     

 

 

 


1 comment: