powershell:ad:healthcheck
Unterschiede
Hier werden die Unterschiede zwischen zwei Versionen angezeigt.
| Beide Seiten der vorigen RevisionVorhergehende ÜberarbeitungNächste Überarbeitung | Vorhergehende Überarbeitung | ||
| powershell:ad:healthcheck [2019/04/02 10:10] – gelöscht henning | powershell:ad:healthcheck [2024/05/27 08:36] (aktuell) – Externe Bearbeitung 127.0.0.1 | ||
|---|---|---|---|
| Zeile 1: | Zeile 1: | ||
| + | ====== ad-healthcheck.ps1 ====== | ||
| + | Das Skript automatisiert den regelmäßig erforderlichen [[ad: | ||
| + | Am längsten dauert die Abfrage der Eventlogs, wenn diese nicht zu groß werden, beschleunigt sich die Ausführung erheblich.\\ | ||
| + | |||
| + | Der Replikationstest funktionert nur von einem Rechner mit Windows 8 mit RSAT-Tools(? | ||
| + | ====== Skript ====== | ||
| + | ====== ad-healthcheck.ps1 ====== | ||
| + | Das Skript automatisiert den regelmäßig erforderlichen [[ad: | ||
| + | |||
| + | Am längsten dauert die Abfrage der Eventlogs, wenn diese nicht zu groß werden, beschleunigt sich die Ausführung erheblich.\\ | ||
| + | |||
| + | Der Replikationstest funktionert nur von einem Rechner mit Windows 8 mit RSAT-Tools(? | ||
| + | ====== Skript ====== | ||
| + | <file powershell ad-healthcheck.ps1> | ||
| + | <# | ||
| + | Autor: | ||
| + | version: 1.0 | ||
| + | |||
| + | Was macht das Skript? | ||
| + | Abfolge der Befehlszeilen für den AD-Healthcheck. | ||
| + | ACHTUNG: Wird das Skript aus der ISE ausgeführt, | ||
| + | #> | ||
| + | $SmtpServer=EIGENER-EMAIL-SERVER | ||
| + | $SmtpSender=EIGENE-ABSENDER-EMAIL | ||
| + | $SmtpRecipient=EIGENE-EMPFÄNGER-EMAIL | ||
| + | $LocalSystem = (Get-WmiObject -Class Win32_ComputerSystem).name | ||
| + | $timestamp=(Get-Date -Format yyyMMdd-Hmmss) | ||
| + | $LogPath=" | ||
| + | $LogFile=" | ||
| + | " " | ||
| + | $start=Get-Date -Format "dddd, dd.MM.yyy H: | ||
| + | " | ||
| + | " | ||
| + | " " | ||
| + | # Skript nur unter einem Domänen-Admin-Account ausführen | ||
| + | if (Get-ADGroupMember " | ||
| + | { | ||
| + | "Das Skript wird unter dem Account von `"" | ||
| + | } | ||
| + | else | ||
| + | { | ||
| + | "Das Skript kann nicht unter dem Account von `"" | ||
| + | Send-MailMessage -SmtpServer " | ||
| + | break #Script wird beendet | ||
| + | } | ||
| + | |||
| + | |||
| + | ##### | ||
| + | # Alle aktuellen Domänencontroller finden: | ||
| + | ## | ||
| + | $domain_dcs = Get-ADDomainController -Filter * | Select-Object hostname | ||
| + | |||
| + | |||
| + | ##### | ||
| + | # DCDIAG | ||
| + | ## | ||
| + | |||
| + | " " | Out-File -Encoding utf8 -filepath $logfile -Append | ||
| + | " " | Out-File -Encoding utf8 -filepath $logfile -Append | ||
| + | " " | Out-File -Encoding utf8 -filepath $logfile -Append | ||
| + | " | ||
| + | " | ||
| + | foreach ($domain_dc in $domain_dcs) | ||
| + | {$check = invoke-command -computername $domain_dc.hostname {dcdiag | Select-String "nicht bestanden" | ||
| + | if ($check -eq $null) | ||
| + | { | ||
| + | "TEST BESTANDEN: DC-Diag auf `"" | ||
| + | } | ||
| + | Else | ||
| + | { | ||
| + | " | ||
| + | } | ||
| + | " " | ||
| + | } | ||
| + | |||
| + | ##### | ||
| + | # REPLIKATION | ||
| + | ## | ||
| + | |||
| + | " " | Out-File -Encoding utf8 -filepath $logfile -Append | ||
| + | " " | Out-File -Encoding utf8 -filepath $logfile -Append | ||
| + | " " | Out-File -Encoding utf8 -filepath $logfile -Append | ||
| + | " | ||
| + | " | ||
| + | " " | Out-File -Encoding utf8 -filepath $logfile -Append | ||
| + | |||
| + | $check=$false | ||
| + | " " | Out-File -Encoding utf8 -filepath $logfile -Append | ||
| + | $replicats = Get-ADReplicationPartnerMetadata -Target * -Partition * | Select-Object server, | ||
| + | $check=$false | ||
| + | $compare=(get-date).AddMinutes(-90) | ||
| + | foreach ($replicat in $replicats) | ||
| + | { | ||
| + | if (($replicat.lastreplicationresult -notlike 0) -or ($replicat.lastreplicationsuccess -lt $compare)) | ||
| + | { | ||
| + | " | ||
| + | $check=$true | ||
| + | } | ||
| + | } | ||
| + | |||
| + | if ($check -eq $false) | ||
| + | { | ||
| + | "TEST BESTANDEN: Bei der Replikation wurden keine Fehler oder Verzögerungen festgestellt." | ||
| + | } | ||
| + | |||
| + | |||
| + | ##### | ||
| + | # BETRIEBSMASTER | ||
| + | ## | ||
| + | | ||
| + | " " | Out-File -Encoding utf8 -filepath $logfile -Append | ||
| + | " " | Out-File -Encoding utf8 -filepath $logfile -Append | ||
| + | " " | Out-File -Encoding utf8 -filepath $logfile -Append | ||
| + | " | ||
| + | " | ||
| + | "Alle Rollen sollen auf dem `" | ||
| + | " " | Out-File -Encoding utf8 -filepath $logfile -Append | ||
| + | # | ||
| + | foreach ($domain_dc in $domain_dcs) | ||
| + | { | ||
| + | $check=Get-ADDomainController $domain_dc.hostname | Select-Object OperationMasterRoles | ||
| + | if ($domain_dc.hostname -like " | ||
| + | { | ||
| + | if ($check.OperationMasterRoles.Count -like " | ||
| + | { | ||
| + | "TEST BESTANDEN: `"" | ||
| + | } | ||
| + | Else | ||
| + | { | ||
| + | " | ||
| + | } | ||
| + | } | ||
| + | Else | ||
| + | { | ||
| + | if ($check.OperationMasterRoles.Count -like " | ||
| + | { | ||
| + | "TEST BESTANDEN: `"" | ||
| + | } | ||
| + | Else | ||
| + | { | ||
| + | " | ||
| + | } | ||
| + | } | ||
| + | } | ||
| + | |||
| + | |||
| + | ##### | ||
| + | # ZEITEINSTELLUNGEN | ||
| + | ## | ||
| + | " " | Out-File -Encoding utf8 -filepath $logfile -Append | ||
| + | " " | Out-File -Encoding utf8 -filepath $logfile -Append | ||
| + | " " | Out-File -Encoding utf8 -filepath $logfile -Append | ||
| + | " | ||
| + | " | ||
| + | " " | Out-File -Encoding utf8 -filepath $logfile -Append | ||
| + | |||
| + | |||
| + | foreach ($domain_dc in $domain_dcs) | ||
| + | { | ||
| + | " | ||
| + | $check = invoke-command -computername $domain_dc.hostname {get-itemproperty " | ||
| + | " | ||
| + | if ($domain_dc.hostname -like " | ||
| + | { | ||
| + | if (($check.type -like " | ||
| + | { | ||
| + | "TEST BESTANDEN: Zeiteinstellungen korrekt" | ||
| + | } | ||
| + | Else | ||
| + | { | ||
| + | " | ||
| + | } | ||
| + | } | ||
| + | Else | ||
| + | { | ||
| + | If ($check.type -like " | ||
| + | { | ||
| + | "TEST BESTANDEN: Zeiteinstellungen korrekt" | ||
| + | } | ||
| + | Else | ||
| + | { | ||
| + | " | ||
| + | } | ||
| + | } | ||
| + | " " | Out-File -Encoding utf8 -filepath $logfile -Append | ||
| + | } | ||
| + | |||
| + | ##### | ||
| + | # Speicherplatz | ||
| + | ## | ||
| + | |||
| + | " " | Out-File -Encoding utf8 -filepath $logfile -Append | ||
| + | " " | Out-File -Encoding utf8 -filepath $logfile -Append | ||
| + | " " | Out-File -Encoding utf8 -filepath $logfile -Append | ||
| + | " | ||
| + | " | ||
| + | " " | Out-File -Encoding utf8 -filepath $logfile -Append | ||
| + | foreach ($domain_dc in $domain_dcs) | ||
| + | { | ||
| + | " | ||
| + | $check=invoke-command -computername $domain_dc.hostname {get-wmiobject win32_volume -Filter ' | ||
| + | $size=($check.FreeSpace)/ | ||
| + | If ($check.FreeSpace -gt 5000000000) | ||
| + | { | ||
| + | "TEST BESTANDEN: Ausreichend freier Speicher auf Partition `"" | ||
| + | } | ||
| + | Else | ||
| + | { | ||
| + | " | ||
| + | } | ||
| + | " " | Out-File -Encoding utf8 -filepath $logfile -Append | ||
| + | } | ||
| + | |||
| + | |||
| + | ##### | ||
| + | # Eventlogs | ||
| + | ## | ||
| + | |||
| + | |||
| + | " " | Out-File -Encoding utf8 -filepath $logfile -Append | ||
| + | " " | Out-File -Encoding utf8 -filepath $logfile -Append | ||
| + | " " | Out-File -Encoding utf8 -filepath $logfile -Append | ||
| + | " | ||
| + | " | ||
| + | " " | Out-File -Encoding utf8 -filepath $logfile -Append | ||
| + | "Es wird lediglich die Zahl aller Meldungen ausgegeben, sowie die Zahl der Fehler pro Log." | Out-File -Encoding utf8 -filepath $logfile -Append | ||
| + | " | ||
| + | " | ||
| + | " " | Out-File -Encoding utf8 -filepath $logfile -Append | ||
| + | $check=$false | ||
| + | foreach ($domain_dc in $domain_dcs) | ||
| + | { | ||
| + | " " | Out-File -Encoding utf8 -filepath $logfile -Append | ||
| + | " | ||
| + | |||
| + | # $Protokoll=" | ||
| + | $Count = (invoke-command -computername $domain_dc.hostname {Get-EventLog " | ||
| + | $ErrorCount = (invoke-command -computername $domain_dc.hostname {Get-EventLog " | ||
| + | " | ||
| + | If ($ErrorCount -notlike " | ||
| + | { | ||
| + | " | ||
| + | $check=$true | ||
| + | } | ||
| + | |||
| + | # $Protokoll=" | ||
| + | $Count = (invoke-command -computername $domain_dc.hostname {Get-EventLog " | ||
| + | $ErrorCount = (invoke-command -computername $domain_dc.hostname {Get-EventLog " | ||
| + | " | ||
| + | If ($ErrorCount -notlike " | ||
| + | { | ||
| + | " | ||
| + | $check=$true | ||
| + | } | ||
| + | |||
| + | # $Protokoll=" | ||
| + | $Count = (invoke-command -computername $domain_dc.hostname {Get-EventLog "DFS Replication" | ||
| + | $ErrorCount = (invoke-command -computername $domain_dc.hostname {Get-EventLog "DFS Replication" | ||
| + | " | ||
| + | If ($ErrorCount -notlike " | ||
| + | { | ||
| + | " | ||
| + | $check=$true | ||
| + | } | ||
| + | |||
| + | # $Protokoll=" | ||
| + | $Count = (invoke-command -computername $domain_dc.hostname {Get-EventLog " | ||
| + | $ErrorCount = (invoke-command -computername $domain_dc.hostname {Get-EventLog " | ||
| + | " | ||
| + | If ($ErrorCount -notlike " | ||
| + | { | ||
| + | " | ||
| + | $check=$true | ||
| + | } | ||
| + | |||
| + | # $Protokoll=" | ||
| + | $Count = (invoke-command -computername $domain_dc.hostname {Get-EventLog "DNS Server" | ||
| + | $ErrorCount = (invoke-command -computername $domain_dc.hostname {Get-EventLog "DNS Server" | ||
| + | " | ||
| + | If ($ErrorCount -notlike " | ||
| + | { | ||
| + | " | ||
| + | $check=$true | ||
| + | } | ||
| + | <# | ||
| + | # $Protokoll=" | ||
| + | $Count = (invoke-command -computername $domain_dc.hostname {Get-EventLog " | ||
| + | $ErrorCount = (invoke-command -computername $domain_dc.hostname {Get-EventLog " | ||
| + | " | ||
| + | If ($ErrorCount -notlike " | ||
| + | { | ||
| + | " | ||
| + | $check=$true | ||
| + | } | ||
| + | #> | ||
| + | |||
| + | # $Protokoll=" | ||
| + | $Count = (invoke-command -computername $domain_dc.hostname {Get-EventLog " | ||
| + | $ErrorCount = (invoke-command -computername $domain_dc.hostname {Get-EventLog " | ||
| + | " | ||
| + | If ($ErrorCount -notlike " | ||
| + | { | ||
| + | " | ||
| + | $check=$true | ||
| + | } | ||
| + | |||
| + | # $Protokoll=" | ||
| + | $Count = (invoke-command -computername $domain_dc.hostname {Get-EventLog " | ||
| + | $ErrorCount = (invoke-command -computername $domain_dc.hostname {Get-EventLog " | ||
| + | " | ||
| + | If ($ErrorCount -notlike " | ||
| + | { | ||
| + | " | ||
| + | $check=$true | ||
| + | } | ||
| + | } | ||
| + | if ($check -eq $false) | ||
| + | { | ||
| + | " " | ||
| + | "TEST BESTADNEN: Es wurden keine Fehler gefunden." | ||
| + | } | ||
| + | |||
| + | ##### | ||
| + | # Global Catalog | ||
| + | ## | ||
| + | |||
| + | " " | Out-File -Encoding utf8 -filepath $logfile -Append | ||
| + | " " | Out-File -Encoding utf8 -filepath $logfile -Append | ||
| + | " " | Out-File -Encoding utf8 -filepath $logfile -Append | ||
| + | " | ||
| + | " | ||
| + | " " | Out-File -Encoding utf8 -filepath $logfile -Append | ||
| + | foreach ($domain_dc in $domain_dcs) | ||
| + | { | ||
| + | $check=Get-ADDomainController dc-essen-01 | select-object name, | ||
| + | if ($check.isglobalcatalog -eq $true) | ||
| + | { | ||
| + | "TEST BESTANDEN: `"" | ||
| + | } | ||
| + | Else | ||
| + | { | ||
| + | " | ||
| + | } | ||
| + | } | ||
| + | |||
| + | $stop=Get-Date -Format "dddd, dd.MM.yyy H: | ||
| + | " " | Out-File -Encoding utf8 -filepath $logfile -Append | ||
| + | " " | Out-File -Encoding utf8 -filepath $logfile -Append | ||
| + | " " | Out-File -Encoding utf8 -filepath $logfile -Append | ||
| + | " | ||
| + | # | ||
| + | |||
| + | ##### | ||
| + | # Ergebnisse per Mail versenden | ||
| + | ## | ||
| + | Send-MailMessage -SmtpServer " | ||
| + | </ | ||
powershell/ad/healthcheck.1554192627.txt.gz · Zuletzt geändert: 2024/05/27 08:34 (Externe Bearbeitung)
