VMware Cloud Community
klee222
Enthusiast
Enthusiast

need help to check and reboot only for VM that uptime is more than 1 day

Hi

Can any one help on this script which was provided in here but the problem is it restart all the VM, and it cannot reboot when the VM in hung.

$vms = Get-VM -Name (Get-Content -Path C:\vm.txt)

Get-Stat -Entity $vms -Stat sys.uptime.latest -Realtime -MaxSamples 1 |

Select @{N='VM';E={$_.Entity.Name}},@{N='Uptime';E={[math]::Round((New-Timespan -Seconds $_.Value).TotalHours)}} |

where{$_.Uptime -gt 24} | %{

    Get-VM -Name $_.VM |

    Restart-VMGuest -Confirm:$false

}

$FA9BE121630E365.png

Really need help here...

Reply
0 Kudos
3 Replies
LucD
Leadership
Leadership

What do you get when you only execute the following ?

$vms = Get-VM -Name (Get-Content -Path C:\vm.txt)

Get-Stat -Entity $vms -Stat sys.uptime.latest -Realtime -MaxSamples 1 |

Select @{N='VM';E={$_.Entity.Name}},@{N='Uptime';E={[math]::Round((New-Timespan -Seconds $_.Value).TotalHours)}}


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
klee222
Enthusiast
Enthusiast

i can only test during non working hours, i'll update tomorrow

Reply
0 Kudos
LucD
Leadership
Leadership

Fyi, the above lines do not change anything, nor do they restart any VM.

Just reporting on the Uptime


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos