diff --git a/Active Directory/Active Directory Health Check/ADHealthCheck.ps1 b/Active Directory/Active Directory Health Check/ADHealthCheck.ps1
index 3a09747..d5ee149 100644
--- a/Active Directory/Active Directory Health Check/ADHealthCheck.ps1
+++ b/Active Directory/Active Directory Health Check/ADHealthCheck.ps1
@@ -1,8 +1,8 @@
<#PSScriptInfo
-.VERSION 1.0
-.GUID 30c7c087-1268-4d21-8bf7-ee25c37459b0
-.AUTHOR Vikas Sukhija
-.COMPANYNAME TechWizard.cloud
+.VERSION 1.2
+.GUID
+.AUTHOR Hubert Cornet
+.COMPANYNAME
.COPYRIGHT
.TAGS
.LICENSEURI
@@ -26,335 +26,334 @@
param (
[string]$Smtphost = $(Read-Host "Entrer l'addresse du serveur SMTP : "),
[string]$from = $(Read-Host "Entrer l'adresse mail de l'expéditeur : "),
- [String[]]$EmailReport = $(Read-Host "Entrer l'adresse mail du ou des destinataire(s) (séparés par une virgule) pour recevoir le rapport"),
- $timeout = "60"
+ [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##################################
-$EmailReport = $EmailReport -split ','
-$report = ".\ADReport.htm"
+$MailReport = $MailReport -split ','
+$Report = ".\AD-Report.htm"
-if((test-path $report) -like $false)
-{
-new-item $report -type file
+If ((test-path $Report) -like $False) {
+ new-item $Report -type File
}
#####################################Get ALL DC Servers#######################
-$getForest = [system.directoryservices.activedirectory.Forest]::GetCurrentForest()
+$GetForest = [system.directoryservices.activedirectory.Forest]::GetCurrentForest()
$DCServers = $getForest.domains | ForEach-Object {$_.DomainControllers} | ForEach-Object {$_.Name}
###############################HTml Report Content############################
-Clear-Content $report
+Clear-Content $Report
-Add-Content $report ""
-Add-Content $report "
"
-Add-Content $report ""
-Add-Content $report 'AD Status Report'
-add-content $report '"
-Add-Content $report ""
-Add-Content $report ""
-add-content $report ""
-add-content $report ""
-add-content $report ""
-add-content $report "Active Directory Health Check"
-add-content $report " | "
-add-content $report "
"
-add-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 " Active Directory Check Health "
+Add-Content $Report " | "
+Add-Content $Report "
"
+Add-Content $Report "
"
-add-content $report ""
-Add-Content $report ""
-Add-Content $report "Identity | "
-Add-Content $report "PingSTatus | "
-Add-Content $report "NetlogonService | "
-Add-Content $report "NTDSService | "
-Add-Content $report "DNSServiceStatus | "
-Add-Content $report "NetlogonsTest | "
-Add-Content $report "ReplicationTest | "
-Add-Content $report "ServicesTest | "
-Add-Content $report "AdvertisingTest | "
-Add-Content $report "FSMOCheckTest | "
-
-Add-Content $report "
"
+Add-Content $Report " "
+Add-Content $Report " "
+Add-Content $Report " Identite | "
+Add-Content $Report " Status du ping | "
+Add-Content $Report " Service Netlogon | "
+Add-Content $Report " Service NTDS | "
+Add-Content $Report " Status Service DNS | "
+Add-Content $Report " Test Netlogons | "
+Add-Content $Report " Test Replication | "
+Add-Content $Report " Test Services | "
+Add-Content $Report " Test Advertising | "
+Add-Content $Report " Test Check FSMO | "
+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
+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 " $Identity | "
- Add-Content $report " Success | "
+ Add-Content $Report " $Identity | "
+ Add-Content $Report " OkK | "
- ##############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 "NetlogonTimeout | "
- 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 "$svcState | "
- }
- else
- {
- Write-Host $DC `t $serviceStatus1.name `t $serviceStatus1.status -ForegroundColor Red
- $svcName = $serviceStatus1.name
- $svcState = $serviceStatus1.status
- Add-Content $report "$svcState | "
- }
- }
- ######################################################
- ##############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 "NTDSTimeout | "
- 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 "$svcState | "
- }
- else
- {
- Write-Host $DC `t $serviceStatus1.name `t $serviceStatus1.status -ForegroundColor Red
- $svcName = $serviceStatus1.name
- $svcState = $serviceStatus1.status
- Add-Content $report "$svcState | "
- }
- }
- ######################################################
- ##############DNS Service Status################
+##############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 " Timeout Netlogon | "
+ 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 " $svcState | "
+ }
+ Else {
+ Write-Host $DC `t $serviceStatus1.name `t $serviceStatus1.status -ForegroundColor Red
+
+ $svcName = $serviceStatus1.name
+ $svcState = $serviceStatus1.status
+
+ Add-Content $Report " $svcState | "
+ }
+ }
+
+##############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 " Timeout NTDS | "
+ 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 " $svcState | "
+ }
+ Else {
+ Write-Host $DC `t $serviceStatus1.name `t $serviceStatus1.status -ForegroundColor Red
+
+ $svcName = $serviceStatus1.name
+ $svcState = $serviceStatus1.status
+
+ Add-Content $Report " $svcState | "
+ }
+ }
+
+##############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 "DNSTimeout | "
- 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 "$svcState | "
- }
- else
- {
- Write-Host $DC `t $serviceStatus1.name `t $serviceStatus1.status -ForegroundColor Red
- $svcName = $serviceStatus1.name
- $svcState = $serviceStatus1.status
- Add-Content $report "$svcState | "
- }
- }
- ######################################################
- ####################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 "NetlogonsTimeout | "
- 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 "NetlogonsPassed | "
- }
- else
- {
- Write-Host $DC `t Netlogons Test Failed -ForegroundColor Red
- Add-Content $report "NetlogonsFail | "
- }
- }
- ########################################################
- ####################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 "ReplicationsTimeout | "
- stop-job $sysvol
- }
- else
- {
- $sysvol1 = Receive-job $sysvol
- if($cmp::instr($sysvol1, "passed test Replications"))
- {
+
+ Wait-Job $serviceStatus -timeout $timeout
+
+ If ($serviceStatus.state -like "Running") {
+ Write-Host $DC `t DNS Server Service TimeOut -ForegroundColor Yellow
+ Add-Content $Report " Timeout DNS | "
+ 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 " $svcState | "
+ }
+ Else {
+ Write-Host $DC `t $serviceStatus1.name `t $serviceStatus1.status -ForegroundColor Red
+
+ $svcName = $serviceStatus1.name
+ $svcState = $serviceStatus1.status
+
+ Add-Content $Report " $svcState | "
+ }
+ }
+
+####################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 " Timeout Netlogons | "
+ 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 " Netlogons OK | "
+ }
+ Else {
+ Write-Host $DC `t Netlogons Test Failed -ForegroundColor Red
+ Add-Content $Report " Netlogons Echec | "
+ }
+ }
+
+####################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 " Timeout Replications | "
+ 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 "ReplicationsPassed | "
- }
- else
- {
- Write-Host $DC `t Replications Test Failed -ForegroundColor Red
- Add-Content $report "ReplicationsFail | "
- }
- }
- ########################################################
- ####################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 "ServicesTimeout | "
- 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 "ServicesPassed | "
- }
- else
- {
- Write-Host $DC `t Services Test Failed -ForegroundColor Red
- Add-Content $report "ServicesFail | "
- }
- }
- ########################################################
- ####################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 "AdvertisingTimeout | "
- stop-job $sysvol
- }
- else
- {
- $sysvol1 = Receive-job $sysvol
- if($cmp::instr($sysvol1, "passed test Advertising"))
- {
+ Add-Content $Report " Replications OK | "
+ }
+ Else {
+ Write-Host $DC `t Replications Test Failed -ForegroundColor Red
+ Add-Content $Report " Replications Echec | "
+ }
+ }
+
+####################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 " Timeout Services | "
+ 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 " Services OK | "
+ }
+ Else {
+ Write-Host $DC `t Services Test Failed -ForegroundColor Red
+ Add-Content $Report " Services Echec | "
+ }
+ }
+
+####################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 " Advertising Timeout | "
+ 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 "AdvertisingPassed | "
- }
- else
- {
- Write-Host $DC `t Advertising Test Failed -ForegroundColor Red
- Add-Content $report "AdvertisingFail | "
- }
- }
- ########################################################
- ####################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 "FSMOCheckTimeout | "
- 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 "FSMOCheckPassed | "
- }
- else
- {
- Write-Host $DC `t FSMOCheck Test Failed -ForegroundColor Red
- Add-Content $report "FSMOCheckFail | "
- }
- }
- ########################################################
-
-}
-else
- {
-Write-Host $DC `t $DC `t Ping Fail -ForegroundColor Red
- Add-Content $report " $Identity | "
- Add-Content $report " Ping Fail | "
- Add-Content $report " Ping Fail | "
- Add-Content $report " Ping Fail | "
- Add-Content $report " Ping Fail | "
- Add-Content $report " Ping Fail | "
- Add-Content $report " Ping Fail | "
- Add-Content $report " Ping Fail | "
- Add-Content $report " Ping Fail | "
- Add-Content $report " Ping Fail | "
-}
-
+ Add-Content $Report " Advertising OK | "
+ }
+ Else {
+ Write-Host $DC `t Advertising Test Failed -ForegroundColor Red
+ Add-Content $Report " Advertising Echec | "
+ }
+ }
+
+####################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 " Timeout Check FSMO | "
+ 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 " Check FSMO OK | "
+ }
+ Else {
+ Write-Host $DC `t FSMOCheck Test Failed -ForegroundColor Red
+ Add-Content $Report " Check FSMO Echec | "
+ }
+ }
+ }
+ Else {
+ Write-Host $DC `t $DC `t Ping Fail -ForegroundColor Red
+ Add-Content $Report " $Identity | "
+ Add-Content $Report " Ping Echec | "
+ Add-Content $Report " Ping Echec | "
+ Add-Content $Report " Ping Echec | "
+ Add-Content $Report " Ping Echec | "
+ Add-Content $Report " Ping Echec | "
+ Add-Content $Report " Ping Echec | "
+ Add-Content $Report " Ping Echec | "
+ Add-Content $Report " Ping Echec | "
+ Add-Content $Report " Ping Echec | "
+ }
}
-Add-Content $report "
"
+Add-Content $Report " "
+
############################################Close HTMl Tables###########################
-Add-content $report "
"
-Add-Content $report ""
-Add-Content $report ""
+Add-Content $Report "
"
+Add-Content $Report " "
+Add-Content $Report ""
+
-########################################################################################
#############################################Send Email#################################
-
-if(($Smtphost) -and ($EmailReport) -and ($from)){
-[string]$body = Get-Content $report
-Send-MailMessage -SmtpServer $Smtphost -From $from -To $EmailReport -Subject "Active Directory Health Monitor" -Body $body -BodyAsHtml
+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
}
-####################################EnD#################################################
-########################################################################################
-
-
\ No newline at end of file