mardi 23 décembre 2014

powershell service if scripts

I am trying to right a script to check if a services is running on one of our servers if the services are running just write an event log, but if the services are stopped run another script outside of this script. I am running to issues with verifying if the services are running. I am sure it's simple but I am not that proficient in if statements. Any help is much appreciated.



# Service Status



$Service='Spooler'

# Check service

((get-service $service).Status -eq 'Running')

$Service2='VMTools'

((get-service $service2).Status -eq 'Running')


Execute Restarting Script if Stopped Service


{ if ($service.Status -eq 'Stopped') $service = False {



elseif($Service2.Status -eq 'Stopped')
"$service2 = False"
}
else {


Z:\SeviceRestart.ps1


} } Write-EventLog -LogName "Service_TestScript" -Source "Service_TestScript" -EventId 1 -Message "Verified $service , $service2 are running"



Aucun commentaire:

Enregistrer un commentaire