Server reboot Script with dependencies via Powershell RRS feed

  • Question

  • Hello.

    For example I got 2 or more servers which I have to reboot in a certain order.

    Server 1


    Server 2


    What I would like to do is:

    Server 1 has been rebooted and is up & running. The script now checks if service A, service B, and so on is running. If all these conditions are set, the script should go on, reboots server 2. If all conditions are set, the script will reboot server 3, ...

    Whats the best way to  do this with powershell?


    Tuesday, May 30, 2017 11:22 AM

All replies

  • Hello,

    The below should get the service to start, if it already hasn't (stolen from another article) - Could you not put something similar between the reboot commands in the script?

    $ServiceName = 'Serenade'
    $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
        if ($arrService.Status -eq 'Running')
            Write-Host 'Service is now Running'

    Let me know if i'm way off.

    Cheers, Ben

    Tuesday, May 30, 2017 11:30 AM