[英]Using the PowerShell host from C# how can I get the output?
[英]Using WMI from PowerShell or C# - how can I get remote host time, including milliseconds?
我需要使用WMI获取包括毫秒在内的远程主机日期和时间。
以下内容不够好:
Get-WmiObject Win32_UTCTime -ComputerName MY_REMOTE_HOST
由于在Win32_UTCTime类派生的Win32_CurrentTime类中未实现毫秒,因此:
毫秒
数据类型:uint32
访问类型:只读
未实现。
此属性是从Win32_CurrentTime继承的。
( https://docs.microsoft.com/zh-cn/previous-versions/windows/desktop/wmitimepprov/win32-currenttime )
如果您有其他建议使用WMI从Powershell或C#获取此信息,我将不胜感激。
WMI类win32_operatingsystem包含一个名为LocalDateTime的属性,该属性还包含毫秒。 您需要将它们转换。
简单样本:
$OS = Get-WmiObject win32_operatingSystem
$OS.ConvertToDateTime($OS.LocalDateTime)
输出是一个DateTime对象,该对象还包含毫秒。
@bluuf的答案是您应该使用的答案,但是作为更复杂的选择,您可以从性能计数器WMI类获取当前日期/时间,如下所示:
$perfTime = Get-CimInstance -Query "Select * FROM Win32_PerfRawData_PerfOS_Processor WHERE Name = '0'"
(Get-Date "01/01/1601").AddTicks($perfTimeime.Timestamp_Sys100NS)
尝试PowerShell远程处理:
$sess = New-PSSession -Credential (Get-Credential)
$dateTime = Invoke-Command -Session $sess -ScriptBlock { Get-Date -Format "o" }
要启用远程处理,请参阅此链接 。
希望能有所帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.