查询域控制器& NTP服务器时间w32tm / monitor格式输出 [英] Query domain controllers & NTP servers time w32tm /monitor format output
问题描述
$ Servers =ntp。我使用以下内容来衡量我们的域控制器和ntp服务器之间的时间偏移量。 xxxxx,ntp.xxxxx,dc1,dc2,dc3,dca,dcb,dcc
$ ListDomains =domain1,domain2
Foreach($ ServerServer $) b $ b $ time =(w32tm / stripchart / dataonly / computer:$ Server /samples:1)[-1].split(\"[\")[0]
$ Server`:`t $ Time #| out-file $ timeFile -append
$ time =
}
ForEach($ ListDomains中的$ Domain){
** $ Domain **
w32tm / monitor /domain:\"$Domain.unisa.edu.au/ nowarn / threads:5
}
这是工作,但输出是可怕的。
域名1
itupw-xxxxx.xxxxxxxxxxxxxx [666.666.6.76:123]:
ICMP:0ms延迟
NTP:-0.0099384s偏移itupw-xxxxx.xxxxxxxxxxxxxx
RefID:itupw-xxxxx.xxxxxxxxxxxxxx [22222222222222]
阶层:5
itupw -xxxxx.xxxxxxxxxxxxxx [999.666.6.76:123]:
ICMP:0ms延迟
NTP:-0.0093544s偏移itupw-xxxxx.xxxxxxxxxxxxxx
RefID:itupw-xxxxx.xxxxxxxxxxxxxx [22222222222222]
层:5
任何人都可以请建议一种格式化的方法,这样数据更容易比较?我们只对Name,ICMP,NTP(offset)感兴趣。
因为NTP盒子是Solaris,所以我们不能使用WMI查询。
谢谢,
Amelia
它读取 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
I'm using the following to measure the time offset between our domain controllers and ntp servers.
$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 }
This is working but the output is horrible. Domain 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
Can anyone please suggest a way of formatting this so the data is easier to compare? We're only interested in Name, ICMP, NTP(offset).
As the NTP boxes are Solaris we can't use WMI queries.
Thanks, Amelia
Gives this a try. It reads w32tm
stdout and parses it into custom objects and puts them into an array. You can just process the array like any other collection of objects.
$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
这篇关于查询域控制器& NTP服务器时间w32tm / monitor格式输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!