0

我正在使用 Virtual Machine Manager 2008 R2,想知道你们中是否有人知道我如何能够通过运行时间搜索虚拟机。

我想找到启动并运行时间最长的机器,以便我可以检查并重新启动任何已经启动超过 6 个月的机器。

也许使用powershell可以做到这一点?GUI 中的任何内容都会更好!

4

1 回答 1

1

更新:刚刚找到了一种更好、更短的方法:

Get-VM | Where-Object { (Get-VMPerformance -VM $_.Name).UpTime.Days -gt 180 } | Select-Object Name

您可以使用 WMI 从每个 VM 获取信息。这将为您提供运行超过 6 个月且无需重新启动的所有 VM:

$LastBootUpTime = (Get-Date).AddMonths(-6)

Get-VM | Where-Object { Test-Connection -ComputerName $_.Name -Count 1 -Quiet} | Foreach-Object{

    $os = Get-WmiObject Win32_OperatingSystem -ComputerName $_.Name

    if( $os.ConvertToDateTime($os.LastBootUpTime) -lt $LastBootUpTime) { $_ }

} | Select-Object Name
于 2012-01-23T14:36:42.903 回答