2012-03-21 4 views
1

다음을 사용하여 도메인 컨트롤러와 ntp 서버 간의 시간 오프셋을 측정합니다.도메인 컨트롤러 및 NTP 서버 쿼리 시간 w32tm/모니터 형식 출력

 
$Servers = "ntp.xxxxx,ntp.xxxxx,dc1,dc2,dc3,dca,dcb,dcc" 
$ListDomains = "domain1","domain2" 

Foreach ($Server in $ListServers) { 
    $time = (w32tm /stripchart /dataonly /computer:$Server /samples:1)[-1].split("[")[0] 
    "$Server`: `t $Time" #| out-file $timeFile -append 
    $time = "" 
} 

ForEach ($Domain in $ListDomains) { 
    "** $Domain **" 
    w32tm /monitor /domain:"$Domain.unisa.edu.au" /nowarn /threads:5 
} 

이것은 작동하지만 출력은 끔찍합니다. 은 도메인 1

itupw-xxxxx.xxxxxxxxxxxxxx[666.666.6.76:123]: 
    ICMP: 0ms delay 
    NTP: -0.0099384s offset from itupw-xxxxx.xxxxxxxxxxxxxx 
    RefID: itupw-xxxxx.xxxxxxxxxxxxxx[22222222222222] 
     Stratum: 5 
itupw-xxxxx.xxxxxxxxxxxxxx[999.666.6.76:123]: 
    ICMP: 0ms delay 
    NTP: -0.0093544s offset from itupw-xxxxx.xxxxxxxxxxxxxx 
     RefID: itupw-xxxxx.xxxxxxxxxxxxxx[22222222222222] 
     Stratum: 5 

는 사람이 데이터를 비교하는 것이 더 쉽습니다 그래서이를 포맷하는 방법을 제안시겠습니까? 우리는 이름, ICMP, NTP (오프셋)에만 관심이 있습니다.

NTP 상자는 Solaris이므로 WMI 쿼리를 사용할 수 없습니다.

덕분에, 아멜리아

답변

4

이 시도 제공합니다. w32tm stdout을 읽고이를 사용자 지정 개체로 구문 분석하여 배열에 저장합니다. 다른 객체 컬렉션처럼 배열을 처리 할 수 ​​있습니다.

 
    $output1 = & w32tm /monitor /domain:yourdomain.com /threads:5 
    $stdOutStart = 8 
    $output = $output1[$stdOutStart..$output1.Length] 
    $timeInfos = @() 

    for ($i = 0 ; $i -lt $output.Length ; $i+=4) { 
     $server = $output[$i].Split(' ')[0] 
     $icmp = $output[$i+1].Trim().Split(' ')[1] 
     $offset = $output[$i+2].Trim().Split(' ')[1] 
     $timeInfos += New-Object PsObject -Property @{ 
      Server = $server 
      ICMP = $icmp 
      Offset = $offset 
     } 
    } 

    $timeInfos