# Code Snippet from aperturescience.su
# Parameters
[Parameter(Position=1, Mandatory=$false, HelpMessage="hostname(s)")]$hosts = "google.com",
# Body
#get the services which are auto and are stopped
$enabledsvc = (Get-WmiObject "win32_service") | Where-Object {($_.startmode -eq "Auto") -and ($_.state -eq "stopped")}
#if we get some services
if ($enabledsvc -ne $null)
{
foreach ($ensvc in $enabledsvc)
{
#set $fix to try if we want to restart services
if ($fix)
{
Write-Verbose "$($a[0].displayname)"
$ensvc.startservice()
send-email "Service $($a[0].displayname) is not running and I tried to fix it" $false
}
else
{
send-email "Service $($a[0].displayname) is not running and I am not fixing it" $false
}
}
}
else
{
send-email "all services running" $true
}
# Code Snippet from aperturescience.su