Windows Powershell automated CPU monitoring and services restart

Today I was having some trouble with a windows server. For some reason it was using a lot of CPU and then froze. I had to restart mysql, apache and sql server everytime and that only when I could logon with remote desktop. I decided to have a script check every now and then if the cpu was increased and came up with the following powershell script:

$cpuutil=(get-counter -Counter "\Processor(_Total)\% Processor Time" -SampleInterval 1 -MaxSamples 5 | select -ExpandProperty countersamples | select -ExpandProperty cookedvalue | Measure-Object -Average).average
Write-Host "CPU: $cpuutil"

If ($cpuutil -ge 90){
	Write-Host "Restarting MySQL, Apache, SQL-Server..."
	Restart-Service httpd, mysqld, sqlservr

I then went and made a scheduled task fire this script every hour and everything seems to be working fine now.