我正在尝试使用以下代码查找 Windows 机器的正常运行时间(上次关机时间):
$computernames = gc LegAservers.txt
foreach ($computername in $computernames) {
$baseKey = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey("LocalMachine",$computername)
$sKey = "System\CurrentControlSet\Control\Windows"
$key = $baseKey.OpenSubKey($sKey)
$kvalue = $key.GetValue("ShutdownTime")
$kvalue
"------------------------------------------"
$baseKey.Close()
}
输出是:
13
152
105
75
132
217
208
1
------------------------------------------
我无法转换这个$kvalue
in DateTime
格式使用:
[DateTime]::FromFileTime($kvalue)
请建议正确的转换方法$kvalue
以日期和时间格式,以便用户可以理解。
$regKey = Get-ItemProperty -Path Registry::HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Windows
$shutDown = $regKey.ShutdownTime
$Int64Value = [System.BitConverter]::ToInt64($shutDown, 0)
$date = [DateTime]::FromFileTime($Int64Value)
$date
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)