我想使用来自一台服务器的powershell命令找到其他服务器的服务器时间。我正在使用以下命令查询另一个服务器,但无法获得所需的结果。
$lastboottime = (Get-WMIObject -Class Win32_OperatingSystem -ComputerName $server -Credential $altcreds -ErrorAction SilentlyContinue).LastBootUpTime
Write-Host $lastboottime
有人可以共享找到其他服务器的最佳方法。SQLServer或SQLServer存储过程中有什么办法
您需要将其转换为有效的DateTime对象,使用ConvertToDateTime
方法...
$WMI = (Get-WMIObject -Class Win32_OperatingSystem -ComputerName $server -Credential $altcreds -ErrorAction SilentlyContinue)
[datetime]::Now - ($WMI.ConvertToDateTime($WMI.LastBootUpTime))
如果您只需要日期:
$WMI.ConvertToDateTime($WMI.LastBootUpTime)