我正在使用以下方法来衡量我们的域 Controller 和ntp服务器之间的时间偏移。
$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
谁能建议一种格式化的方式,以便于比较数据?我们只对名称,ICMP,NTP(偏移)感兴趣。
由于NTP框是Solaris,因此我们不能使用WMI查询。
谢谢,
阿米莉亚
最佳答案
尝试一下。它读取w32tm
stdout并将其解析为自定义对象,并将它们放入数组中。您可以像处理任何其他对象集合一样处理数组。
$ output1 =&w32tm / monitor /domain:yourdomain.com / threads:5
$ stdOutStart = 8
$ output = $ output1 [$ stdOutStart .. $ output1.Length]
$ timeInfos = @()
对于($ 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 + =新对象PsObject-属性@ {
服务器= $ server
ICMP = $ icmp
偏移量= $偏移量
}
}
$ timeInfos
关于powershell - 查询域 Controller 和NTP服务器时间w32tm/显示器格式输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9798009/