@echo off
set itime=0
:start
for /f "tokens=2 delims==" %%a in ('wmic path Win32_PerfFormattedData_PerfOS_Processor get PercentProcessorTime /value^|findstr "PercentProcessorTime"') do set UseCPU=%%a
if %UseCPU% gtr 60 set /a itime=%itime%+1
if %UseCPU% lss 40 set itime=0
if %itime% gtr 30 goto vmrestart
choice /t 60 /d y /m "%date% %time% CPU %UseCPU% %itime% Waiting 60s"
goto start
choice /t 10 /d y /m "%date% %time% Somthing wrong, to end"
goto end
:vmrestart
choice /t 600 /d y /m "%date% %time% Restart finished, to start again"
set itime=0
goto start
:end
pause