使用从w32tm返回的数据

时间:2014-07-20 10:39:34

标签: powershell time

我正在开发一个审计脚本,用于在将新客户服务器作为客户登机之前对其进行审计。目前我正在研究将分析如何在服务器上配置Windows时间的部分。

我需要从PowerShell中获取PowerShell中的一些数据:w32tm /dumpreg /subkey:parameters

然而,什么是回报基本上只是一个表:

Value Name                 Value Type          Value Data
------------------------------------------------------------

ServiceDllUnloadOnStop     REG_DWORD           1
ServiceMain                REG_SZ              SvchostEntry_W32Time
NtpServer                  REG_SZ              time.windows.com,0x9
Type                       REG_SZ              NT5DS
ServiceDll                 REG_EXPAND_SZ       %systemroot%\system32\w32time.dl

如何轻松地从该表中将NtpServerType提取到一个变量中,然后我可以在我的脚本中使用它?

1 个答案:

答案 0 :(得分:2)

您可以使用正则表达式提取它。但是由于这些值显然存储在注册表中(正如您从输出中看到的那样),我只是自己从注册表中提取它们。

$ntpserver = (Get-ItemProperty HKLM:\SYSTEM\CurrentControlSet\Services\W32Time\Parameters).NtpServer
$type = (Get-ItemProperty HKLM:\SYSTEM\CurrentControlSet\Services\W32Time\Parameters).Type

$ntpserver
time.windows.com,0x9

$type
NTP
相关问题