1

以下を使用して、ドメイン コントローラーと ntp サーバー間のタイム オフセットを測定しています。

$Servers = "ntp.xxxxx,ntp.xxxxx,dc1,dc2,dc3,dca,dcb,dcc"
$ListDomains = "ドメイン1","ドメイン2"

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

ForEach ($ListDomains の $Domain) {
    「** $ドメイン **」
    w32tm /monitor /domain:"$Domain.unisa.edu.au" /noarn /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

1 に答える 1

4

これを試してみます。stdout を読み取りw32tm、それをカスタム オブジェクトに解析して配列に配置します。他のオブジェクトのコレクションと同じように配列を処理できます。

    $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 @{
            サーバー = $サーバー
            ICMP = $icmp
            オフセット = $offset
        }
    }

    $timeInfos
于 2012-03-21T10:24:55.080 に答える