Link to home
Start Free TrialLog in
Avatar of Allanore
Allanore

asked on

Time Sync PowerShell Script

I made a script that will take the time of the PDC and send an email to me with the Time stamp. I verify the timestamp with the time received of the email alert to make sure the time is in sync (at least by a few minutes) for that client. Is there a way to add an ALERT! flag to the header if the time is off by a few minutes?


Powershell Script that I have:

$logfile="C:\users\public\tempinfo.txt"

Get-date | Out-file $logfile

$client =  (gwmi WIN32_ComputerSystem).Domain

$smtpServer = "192.168.0.1"
$smtpFrom = "email@email.com"
$smtpTo = "recipient@mail.com"
$messageSubject = "Time Synchronization Test - $client "

$message = New-Object System.Net.Mail.MailMessage $smtpfrom, $smtpto
$message.Subject = $messageSubject
$message.IsBodyHTML = $true

$message.Body = get-content $logfile

$smtp = New-Object Net.Mail.SmtpClient($smtpServer)
$smtp.Send($message)

Remove-Item $logfile
Avatar of Leon Fester
Leon Fester
Flag of South Africa image

Is there a way to add an ALERT! flag to the header if the time is off by a few minutes?

You cannot modify the header of the email as it is created by the SMTP server when the email is processed. Unless you need the header somewhere else.

Not sure what issue you are trying to resolve but on a separate topic; if you have a PDC then you have Active Directory installed. Active Directory allows a time sync difference of 5 minutes on each side of the PDC time. If the time is out by more than this value then the Host OS will try to re-sync the time from the PDC.
ASKER CERTIFIED SOLUTION
Avatar of Rich Weissler
Rich Weissler

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial