diff --git a/Active Directory/ADHealthCheck.ps1 b/Active Directory/ADHealthCheck.ps1 deleted file mode 100644 index d5ee149..0000000 --- a/Active Directory/ADHealthCheck.ps1 +++ /dev/null @@ -1,359 +0,0 @@ -<#PSScriptInfo -.VERSION 1.2 -.GUID -.AUTHOR Hubert Cornet -.COMPANYNAME -.COPYRIGHT -.TAGS -.LICENSEURI -.PROJECTURI -.ICONURI -.EXTERNALMODULEDEPENDENCIES -.REQUIREDSCRIPTS -.EXTERNALSCRIPTDEPENDENCIES -.RELEASENOTES h -.PRIVATEDATA -#> - -<# -.DESCRIPTION - Date: 18/10/2023 - Active Directory Health Status Check - Satus: Ping,Netlogon,NTDS,DNS,DCdiag Test(Replication,sysvol,Services) -#> - -###############################Paramters#################################### -param ( - [string]$Smtphost = $(Read-Host "Entrer l'addresse du serveur SMTP : "), - [string]$from = $(Read-Host "Entrer l'adresse mail de l'expéditeur : "), - [String[]]$MailReport = $(Read-Host "Entrer l'adresse mail du ou des destinataire(s) (séparés par une virgule) pour recevoir le rapport"), - $timeout = "120" -) - -###########################Define Variables################################## -$MailReport = $MailReport -split ',' -$Report = ".\AD-Report.htm" - -If ((test-path $Report) -like $False) { - new-item $Report -type File -} - -#####################################Get ALL DC Servers####################### -$GetForest = [system.directoryservices.activedirectory.Forest]::GetCurrentForest() -$DCServers = $getForest.domains | ForEach-Object {$_.DomainControllers} | ForEach-Object {$_.Name} - -###############################HTml Report Content############################ -Clear-Content $Report - -Add-Content $Report "" -Add-Content $Report " " -Add-Content $Report " " -Add-Content $Report ' Rapport Status Active Directory ' -Add-Content $Report ' " -Add-Content $Report " " -Add-Content $Report " " -Add-Content $Report " " -Add-Content $Report " " -Add-Content $Report " " -Add-Content $Report " " -Add-Content $Report "
" -Add-Content $Report " Active Directory Check Health " -Add-Content $Report "
" - -Add-Content $Report " " -Add-Content $Report " " -Add-Content $Report " " -Add-Content $Report " " -Add-Content $Report " " -Add-Content $Report " " -Add-Content $Report " " -Add-Content $Report " " -Add-Content $Report " " -Add-Content $Report " " -Add-Content $Report " " -Add-Content $Report " " -Add-Content $Report " " - -################Ping Test################################################################ -Foreach ($DC in $DCServers) { - $Identity = $DC - Add-Content $Report " " - - If ( Test-Connection -ComputerName $DC -Count 1 -ErrorAction SilentlyContinue ) { - Write-Host $DC `t $DC `t Ping Success -ForegroundColor Green - - Add-Content $Report " " - Add-Content $Report " " - -##############Netlogon Service Status################ - $serviceStatus = start-job -scriptblock {get-service -ComputerName $($args[0]) -Name "Netlogon" -ErrorAction SilentlyContinue} -ArgumentList $DC - Wait-Job $serviceStatus -timeout $timeout - - If ($serviceStatus.state -like "Running") { - Write-Host $DC `t Netlogon Service TimeOut -ForegroundColor Yellow - Add-Content $Report " " - Stop-Job $serviceStatus - } - Else { - $serviceStatus1 = Receive-job $serviceStatus - If ($serviceStatus1.status -eq "Running") { - Write-Host $DC `t $serviceStatus1.name `t $serviceStatus1.status -ForegroundColor Green - - $svcName = $serviceStatus1.name - $svcState = $serviceStatus1.status - - Add-Content $Report " " - } - Else { - Write-Host $DC `t $serviceStatus1.name `t $serviceStatus1.status -ForegroundColor Red - - $svcName = $serviceStatus1.name - $svcState = $serviceStatus1.status - - Add-Content $Report " " - } - } - -##############NTDS Service Status################ - $serviceStatus = start-job -scriptblock {get-service -ComputerName $($args[0]) -Name "NTDS" -ErrorAction SilentlyContinue} -ArgumentList $DC - Wait-Job $serviceStatus -timeout $timeout - - If ($serviceStatus.state -like "Running") { - Write-Host $DC `t NTDS Service TimeOut -ForegroundColor Yellow - Add-Content $Report " " - Stop-Job $serviceStatus - } - Else { - $serviceStatus1 = Receive-job $serviceStatus - - If ($serviceStatus1.status -eq "Running") { - Write-Host $DC `t $serviceStatus1.name `t $serviceStatus1.status -ForegroundColor Green - - $svcName = $serviceStatus1.name - $svcState = $serviceStatus1.status - - Add-Content $Report " " - } - Else { - Write-Host $DC `t $serviceStatus1.name `t $serviceStatus1.status -ForegroundColor Red - - $svcName = $serviceStatus1.name - $svcState = $serviceStatus1.status - - Add-Content $Report " " - } - } - -##############DNS Service Status################ - $serviceStatus = start-job -scriptblock {get-service -ComputerName $($args[0]) -Name "DNS" -ErrorAction SilentlyContinue} -ArgumentList $DC - - Wait-Job $serviceStatus -timeout $timeout - - If ($serviceStatus.state -like "Running") { - Write-Host $DC `t DNS Server Service TimeOut -ForegroundColor Yellow - Add-Content $Report " " - Stop-Job $serviceStatus - } - Else { - $serviceStatus1 = Receive-job $serviceStatus - - If ($serviceStatus1.status -eq "Running") { - Write-Host $DC `t $serviceStatus1.name `t $serviceStatus1.status -ForegroundColor Green - - $svcName = $serviceStatus1.name - $svcState = $serviceStatus1.status - - Add-Content $Report " " - } - Else { - Write-Host $DC `t $serviceStatus1.name `t $serviceStatus1.status -ForegroundColor Red - - $svcName = $serviceStatus1.name - $svcState = $serviceStatus1.status - - Add-Content $Report " " - } - } - -####################Netlogons status################## - Add-Type -AssemblyName microsoft.visualbasic - - $cmp = "microsoft.visualbasic.strings" -as [type] - $sysvol = start-job -scriptblock {dcdiag /test:netlogons /s:$($args[0])} -ArgumentList $DC - - Wait-Job $sysvol -timeout $timeout - - If ($sysvol.state -like "Running") { - Write-Host $DC `t Netlogons Test TimeOut -ForegroundColor Yellow - Add-Content $Report " " - Stop-Job $sysvol - } - Else { - $sysvol1 = Receive-job $sysvol - - If ($cmp::instr($sysvol1, "passed test NetLogons")) { - Write-Host $DC `t Netlogons Test passed -ForegroundColor Green - Add-Content $Report " " - } - Else { - Write-Host $DC `t Netlogons Test Failed -ForegroundColor Red - Add-Content $Report " " - } - } - -####################Replications status################## - Add-Type -AssemblyName microsoft.visualbasic - - $cmp = "microsoft.visualbasic.strings" -as [type] - $sysvol = start-job -scriptblock {dcdiag /test:Replications /s:$($args[0])} -ArgumentList $DC - - Wait-Job $sysvol -timeout $timeout - If ($sysvol.state -like "Running") { - Write-Host $DC `t Replications Test TimeOut -ForegroundColor Yellow - Add-Content $Report " " - Stop-Job $sysvol - } - Else { - $sysvol1 = Receive-job $sysvol - - If ($cmp::instr($sysvol1, "passed test Replications")) { - Write-Host $DC `t Replications Test passed -ForegroundColor Green - Add-Content $Report " " - } - Else { - Write-Host $DC `t Replications Test Failed -ForegroundColor Red - Add-Content $Report " " - } - } - -####################Services status################## - Add-Type -AssemblyName microsoft.visualbasic - - $cmp = "microsoft.visualbasic.strings" -as [type] - $sysvol = start-job -scriptblock {dcdiag /test:Services /s:$($args[0])} -ArgumentList $DC - - Wait-Job $sysvol -timeout $timeout - - If ($sysvol.state -like "Running") { - Write-Host $DC `t Services Test TimeOut -ForegroundColor Yellow - Add-Content $Report " " - Stop-Job $sysvol - } - Else { - $sysvol1 = Receive-job $sysvol - - If ($cmp::instr($sysvol1, "passed test Services")) { - Write-Host $DC `t Services Test passed -ForegroundColor Green - Add-Content $Report " " - } - Else { - Write-Host $DC `t Services Test Failed -ForegroundColor Red - Add-Content $Report " " - } - } - -####################Advertising status################## - Add-Type -AssemblyName microsoft.visualbasic - - $cmp = "microsoft.visualbasic.strings" -as [type] - $sysvol = start-job -scriptblock {dcdiag /test:Advertising /s:$($args[0])} -ArgumentList $DC - - Wait-Job $sysvol -timeout $timeout - - If ($sysvol.state -like "Running") { - Write-Host $DC `t Advertising Test TimeOut -ForegroundColor Yellow - Add-Content $Report " " - Stop-Job $sysvol - } - Else { - $sysvol1 = Receive-job $sysvol - - If ($cmp::instr($sysvol1, "passed test Advertising")) { - Write-Host $DC `t Advertising Test passed -ForegroundColor Green - Add-Content $Report " " - } - Else { - Write-Host $DC `t Advertising Test Failed -ForegroundColor Red - Add-Content $Report " " - } - } - -####################FSMOCheck status################## - Add-Type -AssemblyName microsoft.visualbasic - - $cmp = "microsoft.visualbasic.strings" -as [type] - $sysvol = start-job -scriptblock {dcdiag /test:FSMOCheck /s:$($args[0])} -ArgumentList $DC - - Wait-Job $sysvol -timeout $timeout - - If ($sysvol.state -like "Running") { - Write-Host $DC `t FSMOCheck Test TimeOut -ForegroundColor Yellow - Add-Content $Report " " - Stop-Job $sysvol - } - Else { - $sysvol1 = Receive-job $sysvol - - If ($cmp::instr($sysvol1, "passed test FsmoCheck")) { - Write-Host $DC `t FSMOCheck Test passed -ForegroundColor Green - Add-Content $Report " " - } - Else { - Write-Host $DC `t FSMOCheck Test Failed -ForegroundColor Red - Add-Content $Report " " - } - } - } - Else { - Write-Host $DC `t $DC `t Ping Fail -ForegroundColor Red - Add-Content $Report " " - Add-Content $Report " " - Add-Content $Report " " - Add-Content $Report " " - Add-Content $Report " " - Add-Content $Report " " - Add-Content $Report " " - Add-Content $Report " " - Add-Content $Report " " - Add-Content $Report " " - } -} - -Add-Content $Report " " - -############################################Close HTMl Tables########################### -Add-Content $Report "
Identite Status du ping Service Netlogon Service NTDS Status Service DNS Test Netlogons Test Replication Test Services Test Advertising Test Check FSMO
$Identity OkK Timeout Netlogon $svcState $svcState Timeout NTDS $svcState $svcState Timeout DNS $svcState $svcState Timeout Netlogons Netlogons OK Netlogons Echec Timeout Replications Replications OK Replications Echec Timeout Services Services OK Services Echec Advertising Timeout Advertising OK Advertising Echec Timeout Check FSMO Check FSMO OK Check FSMO Echec $Identity Ping Echec Ping Echec Ping Echec Ping Echec Ping Echec Ping Echec Ping Echec Ping Echec Ping Echec
" -Add-Content $Report " " -Add-Content $Report "" - - -#############################################Send Email################################# -If (($Smtphost) -and ($MailReport) -and ($From)) { - [string]$body = Get-Content $Report - Send-MailMessage -SmtpServer $Smtphost -From $From -To $MailReport -Subject "Active Directory Health Monitor" -Body $body -BodyAsHtml -} - \ No newline at end of file