我正在尝试按照post here来解析w32tm的输出,并将这些项目安排在一个易于阅读的数据表中。我注意到我没有按顺序排列,错误地将结果放在不同的列中。
在测试中,如果我输入:
w32tm /monitor /domain:mydomain.com.au /Threads:5
我得到每个服务器的订购和格式正确,它的NTP偏移和ICMP延迟完美呈现,如下所示:
kesvm001.mydomain.com.au[xxx.xxx.xxx.x:xxx]:
ICMP: 37ms delay
NTP: -0.0446479s offset from VM021.mydomain.com.au
RefID: VM021.mydomain.com.au [xxx.xxx.xx.xxx]
Stratum: 4
VM033.mydomain.com.au[xxx.xxx.xxx.xx:xxx]:
ICMP: 50ms delay
NTP: -0.0640493s offset from VM021.mydomain.com.au
RefID: 80.84.77.86.rev.sfr.net [xx.xx.xx.xx]
Stratum: 2
如果我这样做:
$output = & w32tm /monitor /domain:mydomain.com.au /Threads:5
$output
我可以解释它的作用的唯一方法是它似乎也输出所有详细信息......
Getting AD DC list for mydomain.com.au
Analyzing:Analyzing:Analyzing:Analyzing:Analyzing:Analyzing:Analyzing:Analyzing:Analyzing:Analyzing:Analyzing:Analyzing:Analyzing:Analyzing:Analyzing:Analyzing:Analyzing:Analyzing:delayoffset from VM021.mydomain.com.au
Stratum: 4
1 2 -- (0 of 48)
11 12 3 (9 of 48)
16 13 17 (14 of 48)
21 18 20 (18 of 48)
26 18 27 (24 of 48)
26 18 28 (25 of 48)
26 18 30 (27 of 48)
26 18 31 (28 of 48)
26 18 32 (29 of 48)
26 18 32 (29 of 48)
33 34 32 (31 of 48)
39 40 41 (38 of 48)
42 46 41 (43 of 48)
42 -- 41 (46 of 48)
-- -- 41 (47 of 48)
-- -- 41 (47 of 48)
-- -- 41 (47 of 48)
-- -- 41 (47 of 48)
kesvm001.mydomain.com.au[xxx.xxx.xxx.xxx:xxx]:
ICMP: 37ms
NTP: -0.1127470s RefID: VM021.mydomain.com.au [192.168.48.150]
VM033.mydomain.com.au[xxx.xxx.xxdelayoffset from VM021.mydomain.com.au
Stratum: 2
delayoffset from VM021.mydomain.com.au
Stratum: 4
delayoffset from VM021.mydomain.com.au
Stratum: 3
delayoffset from VM021.mydomain.com.au
Stratum: 4
delayoffset from VM021.mydomain.com.au
Stratum: 4
delayoffset from VM021.mydomain.com.au
Stratum: 4
delayoffset from VM021.mydomain.com.au
Stratum: 4
delayoffset from VM021.mydomain.com.au
我认为可能与使用多个线程有关,但即使将Threads更改为1也没有区别。到底发生了什么事?我正在做的事情(我想)正在采取通常出现在屏幕上的任何输出,并把它放在变量中......
答案 0 :(得分:0)
它实际上做了它应该做的事情。它是所有输出的阴道。如果您将在cmd控制台中运行它,您会注意到在显示结果之前,它实际上会打印出一些进度信息。在PowerShell中它可以捕获所有内容。如果你想过滤一些东西,你可以这样做:
$output = & w32tm /monitor /domain:mydomain.com /threads:5
$output | Where-Object{!$_.StartsWith("Analyzing") -and !$_.StartsWith(" ") -and !$_.Contains(" of ") -and !$_.StartsWith("Stratum") -and !$_.StartsWith("delayoffset")}