Write-Host ""
$Target_rep = hostname
$date_rep = Get-Date
$Filename_rep = "C:\Log_Replication\" + $Target_rep + "_" + $date_rep.Hour + $date_rep.Minute + "_" + $Date_rep.Day + "-" + $Date_rep.Month + "-" + $Date_rep.Year + ".hta"
Clear-Host;
Write-host ""
Write-host "Nhap bat ky ky tu nao, se thuc hien kiem tra Replication tai may chu Domain controller hien tai"
write-host "Nhap '*' de thuc hien kiem tra Replication tren tat ca Domain Controller." -foregroundcolor red -backgroundcolor yellow
$SERVERS = (Read-Host "Kiem tra Replication tren Domain Controller")
if ($SERVERS -ne "*")
{
Write-host ""
write-host "Dang kiem tra........"
$workfile = repadmin.exe /showrepl /csv}
else
{
Write-host ""
write-host "Dang kiem tra........"
#Check the Replication with Repadmin
$workfile = repadmin.exe /showrepl * /csv
}
#if ($error -eq $null)
#{
$Report_Rep = @"
TEST REPLICATION
$Target_rep = hostname
$date_rep = Get-Date
$Filename_rep = "C:\Log_Replication\" + $Target_rep + "_" + $date_rep.Hour + $date_rep.Minute + "_" + $Date_rep.Day + "-" + $Date_rep.Month + "-" + $Date_rep.Year + ".hta"
Clear-Host;
Write-host ""
Write-host "Nhap bat ky ky tu nao, se thuc hien kiem tra Replication tai may chu Domain controller hien tai"
write-host "Nhap '*' de thuc hien kiem tra Replication tren tat ca Domain Controller." -foregroundcolor red -backgroundcolor yellow
$SERVERS = (Read-Host "Kiem tra Replication tren Domain Controller")
if ($SERVERS -ne "*")
{
Write-host ""
write-host "Dang kiem tra........"
$workfile = repadmin.exe /showrepl /csv}
else
{
Write-host ""
write-host "Dang kiem tra........"
#Check the Replication with Repadmin
$workfile = repadmin.exe /showrepl * /csv
}
#if ($error -eq $null)
#{
$Report_Rep = @"
verify AD replication status on Domain controller:$Target_rep
Version 1.0 by Pham Duy Hieu
Report generated on $Date_rep
"@
$results = ConvertFrom-Csv -InputObject $workfile | where {$_.'Number of Failures' -ge 1}
$CountFail = $results.count
#$results_show = ConvertFrom-Csv -InputObject $workfile
write-host ""
#$results_show | select "Source DSA", "Naming Context", "Destination DSA" ,"Number of Failures", "Last Failure Time", "Last Success Time", "Last Failure Status"
#$results_show | select "Source DSA", "Naming Context", "Destination DSA" ,"Number of Failures", "Last Failure Time", "Last Success Time", "Last Failure Status" | ConvertTo-Html > C:\Log_Replication\Show_Test_replicate.hta
#Here you set the tolerance level for the report
$results = $results | where {$_.'Number of Failures' -gt 1 }
cls
if ($results -ne $null ) {
write-host ""
write-host "Replication Errors: $CountFail" -foregroundcolor red -backgroundcolor yellow
write-host ""
#$results | select "Source DC", "Naming Context", "Destination DC" ,"Number of Failures", "Last Failure Time", "Last Success Time", "Last Failure Status"
#$results | select "Source DC", "Naming Context", "Destination DC" ,"Number of Failures", "Last Failure Time", "Last Success Time", "Last Failure Status" | ConvertTo-Html > C:\Log_Replication\Test_replicate_fail.hta
$SourceDSA = $results | select 'Source DSA'
#write-host $SourceDSA
} else {
write-host ""
write-host "There were no Replication Errors" -foregroundcolor red -backgroundcolor yellow
write-host ""
}
#===========================================================================
$Report_rep+= @"
Success
"@
#============================================================================
$success = ConvertFrom-Csv -InputObject $workfile | where {$_.'Number of Failures' -le 0}
#write-host success_count = $success.count
foreach ($row in $success)
{
$SourceDSA = $row.'Source DSA'
$NamingContext = $row.'Naming Context'
$DestinationDSA = $row.'Destination DSA'
$NumberofFailures = $row.'Number of Failures'
$LastFailureTime = $row.'Last Failure Time'
$LastSuccessTime = $row.'Last Success Time'
$LastFailureStatus = $row.'Last Failure Status'
#============================================================================
$Report_rep+= "
$Report_rep+= "
" $Report_rep+= "
" $Report_rep+= "
" $Report_rep+= "
" $Report_rep+= "
" $Report_rep+= "
" $Report_rep+= "
" $Report_rep+= "
"}
#===================================================================================
$Report_rep+= @"
"@
#==============================================================
$Report_rep+= @"
Failure
"@
#==================================================================
$fail = ConvertFrom-Csv -InputObject $workfile | where {$_.'Number of Failures' -ge 1}
#write-host $fail_count = $fail.count
foreach ($row_fail in $fail)
{
$SourceDSA_fail = $row_fail.'Source DSA'
$NamingContext_fail = $row_fail.'Naming Context'
$DestinationDSA_fail = $row_fail.'Destination DSA'
$NumberofFailures_fail = $row_fail.'Number of Failures'
$LastFailureTime_fail = $row_fail.'Last Failure Time'
$LastSuccessTime_fail = $row_fail.'Last Success Time'
$LastFailureStatus_fail = $row_fail.'Last Failure Status'
#==============================================================
$Report_rep+= "
$Report_rep+= "
" $Report_rep+= "
" $Report_rep+= "
" $Report_rep+= "
" $Report_rep+= "
" $Report_rep+= "
" $Report_rep+= "
" $Report_rep+= "
"
#==============================================================
}
$Report_rep+= @"
"@
#==============================================================
$Report+= @"
"@
write-host ""
write-host "Dang tao Report........."
$Report_rep | out-file -encoding ASCII -filepath $Filename_rep
write-host ""
Write-Host "Report xem tai folder C:\Log_Replication" -foregroundcolor red -backgroundcolor yellow
write-host ""
#}else
#{write-host $error}
Không có nhận xét nào:
Đăng nhận xét