how to get Time source DCs in domain
hi friends,
i got below script checkout time source of domain controllers in domain.
but script appending output file , instead of need override output file every time.
or if possible, can below format time source in output file?
time source dc102dc104.contoso.org
"*********************************************************"
time source dc102
dc104.contoso.org
*********************************************************
time source dc101
dc104.contoso.org
*********************************************************
any me appreciated.
================================
function checktimeservers {
begin {}
process {
$server = "$_"
if ($_ -ne "") {
write-host "checking time source of $server, pasting output in $($logfile)"
$timeserver = w32tm /query /computer:$server /source
write-output "[$(get-date -format g)]: server $($server) gets time $($timeserver)" >> $logfile
}
}
end {}
}
cls
$scriptpath = split-path $myinvocation.mycommand.path
$logfile = $scriptpath+"\output.txt"
get-content $scriptpath"\serverlist.txt" | checktimeservers
hi,
to change format of output:
write-output "time source for server $($server) `n $($timeserver)" `n ********************************************************* > $logfile
regards,
yan li
regards, yan li
Windows Server > Windows PowerShell
Comments
Post a Comment