Years ago I would for a company that felt it needed a domain
controller at every remote location against the advice of all of the employed
SEs and SAs. This caused some issues
being that there were 90 domain controllers in the domain. On an almost daily basis we had domain controllers
go off line and start the 60 count down to tombstone. So to make sure my co-workers were doing
their job I wrote this to prevent a forced rip out of a tomb-stoned domain
controller. The original script was very
simple only running RepAdmin. Since then
I have put in some additions like dcddiag.
It also will provide a list of machines that are currently in the
computers container. As you may know no
group policies can be applied to these machines. This was an addition so I could keep the
helpdesk honest. Hope this helps.
###############################################################################
# Script Name: Domain_Replication_Summary.ps1
# Created On: 02/15/2009
# Author: Joshua & Matthew
# Purpose: Get Replication Summary and email to a
group
# Last Modified:
02/15/2016
# Last Modifier:
Joshua
###############################################################################
#Import-Modules
Import-Module ActiveDirectory
Add-PSSnapin Quest.ActiveRoles.ADManagement
#Variables
$date = Get-Date -Format yyyyMMdd
$aging =
(Get-Date).adddays(-8).ToString("yyyyMMdd")
$aging2 =
(Get-Date).adddays(-8).ToString("yyyyMMdd")
$log =
"C:\ST_Logs\Replication_Summary_Report_'$date'.txt"
$log2 =
"C:\ST_Logs\DCDiag_Summary_Report_'$date'.txt"
$smtp = "YourSMTP.YourDomain.com"
$to = "Domain_Replication_Summary@ YourDomain.com "
$from = "DNR_Reports@ YourDomain.com "
$subject = "Domain Health Check $date"
$staging = dsquery computer "CN=Computers,DC=YourDomain,DC=com"
-name *
$bodystart = "Please see attached
logs.
Below computer accounts are in the Computers Container and need to be moved.
"
Below computer accounts are in the Computers Container and need to be moved.
"
$body = $bodystart+$staging
# Run RepAdmin Commands
repadmin /replsummary | Out-File -FilePath $log
dcdiag /e /q /n:YourDomain.com | Out-File -FilePath $log2
# Remove all reports greater than 7 days old
Remove-Item "C:\PS_Scripts\Temp_Working\Replication_Summary_Reports\Replication_Summary_Report_'$aging'.txt"
-recurse
Remove-Item "C:\PS_Scripts\Temp_Working\Replication_Summary_Reports\Replication_Summary_Report_'$aging2'.txt"
-recurse
Remove-Item "C:\PS_Scripts\Temp_Working\Replication_Summary_Reports\DCDiag_Summary_Report_'$aging'.txt"
-recurse
Remove-Item "C:\PS_Scripts\Temp_Working\Replication_Summary_Reports\DCDiag_Summary_Report_'$aging2'.txt"
-recurse
#### Now send the email using \> Send-MailMessage
send-MailMessage -SmtpServer $smtp -To $to -From $from
-Subject $subject -Body $body -BodyAsHtml -Priority normal -Attachments $log,
$log2
No comments:
Post a Comment