Score:0

run task in the background

in flag

i have powershell script that check if the service is up and of not it starts it up,

$ServiceName = 'mapguideserver3.1'
$arrService = Get-Service -Name $ServiceName

while ($arrService.Status -ne 'Running')
{

    Start-Service $ServiceName
    write-host $arrService.status
    write-host 'Service starting'
    Start-Sleep -seconds 60
    $arrService.Refresh()
    if ($arrService.Status -eq 'Running')
    {
        Write-Host 'Service is now Running'
    }

}

i tried to use it in a task scheduler as system startup and right click and run , by setting "allow it to run on demand"

i saw that the task status is "running" and after some time it changes to "ready", when i checked after some time the task doesn't changes back the service if its stopped.

how can i run the script that it will run forever?

in flag
Why don't you just configure the service to be restarted automatically?
in flag
It start automaticlly after reboot but some times the service stops
in flag
And you don't have a recovery action configured for that service?
in flag
Ok i didnt know thats possible thanks
cn flag
`i saw that the task status is "running" and after some time it changes to "ready", ` Some time? Like minutes or hours? Tasks have a maximum run time. That should be checked/validated first. Also if the while loop is false, the service is running and the script exits, that is the expected behavior.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.