Hi, I need a help on rebooting few VM machine by checking thier uptimes if more than 1 days.
I have set a schedule to reboot those machine by 7am but some times one or two machines will fail to do so (Due hung or schedule command fails).
And we cannot reboot for a same machine twice, so i need a script to run by schedule to check if any VM machine uptimes is more than 1 day then need to reboot (Force reboot are accepted)
Can somene help me on this, simple scripting will do.
Hi
Here is the result..
Ok, try this way now
$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
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi
After hit enter 2-3 times, it stop at here...no movement..?
You forgot the enter the closing curly brace, so the PS engine keeps prompting till the code block is closed.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Here is the result...and the result? i don't know it work or not.
and i have 3 VM, but only 2 is scan ?
No, only 2 seem to have passed the Where-clause.
You should be able to see in the Web Client if the guest OS was restarted.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi, it means it only show the success scanned VM only?
Cannot complete operation becasue VMware tools is not running in this virtual machine..?
when first time run is ok, after that it prompt something and i forget what is that i lick "y"
Then i test run second time for few time that a error like above came out..
Help....
Yes, it only shows the VMs that came through the Where-clause.
If you don't have the VMware Tools installed in those guests, you will have to cold restart the VM.
Use the Restart-VM cmdlet instead of the Restart-VmGuest cmdlet.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi
May i know how do i apply that script ?
I'm not good in this
Thanks you
hope this would help you.
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-VM -Confirm:$false
}
as per LUC you do a replacement. Hope I am correct
Hi
I'm using LucD script and there are two problem with this
1) It restart all VM even the the VM are not uptime more than 1 day
2) For the the VM "XP10" the uptime is more than 1 day but could't reboot.
*There are already have a task schedule which reboot all VM by 7am, but due to some VM are not reboot success (Because it Hung after restart) i need help on this to make sure for those are not reboot successfully it will reboot again)
Hi LucD
There are two problem with the script
1) It restart all VM even the the VM are not uptime more than 1 day
2) For the the VM "XP10" the uptime is more than 1 day but could't reboot. *There are already have a task schedule which reboot all VM by 7am, but due to some VM are not reboot success (Because it Hung after restart)
*i need help on this to make sure for those are not reboot successfully it will reboot again)
Hi LucD
Need help..