PowerShell Script - Service Restarter

Version 1
    Share This:

    Summary

    This is a Microsoft PowerShell script that is used to restart Windows services on local and/or remote computers. It can be used to restart one service on one computer or multiple services on multiple computers in a rolling fashion. It is designed to allow for zero downtime application restarts in a high availability environment.

     

    Download the latest version here:  Service_Restarter.ps1

    Example log file:  Service_Restarter.log

    Build Information

    The original script was built on Windows Server 2012. It was originally written to restart the same service (BMC Remedy Email Engine) across multiple servers, being automated as a Windows Scheduled Task. It has recently been updated to accept a pipe (|) delimited list of targets (host|serviceName).

    Example:  host1|serviceName1,host1|serviceName2,host2|serviceName1,host2|serviceName3

     

    The original single-service script has been used in production for 2 years. The newly updated version that uses host|serviceName pairs has only been tested in a single server environment at this time. The included log was created from the script using the published configuration to demonstrate the flow. During that run I restarted multiple BMC Remedy and Tomcat services. I utilized both my virtual machine’s host name and ‘localhost’ to simulate an environment with multiple servers. In reality I was restarting the same services on the same host however this validated the script logic can successfully handle different host|serviceName pairs.

    Logging

    The runtime variables, script flow and service status are written to a log file. BareTail is a great utility for watching log files in realtime on Windows.

    What’s Included

    Name

    Object Type

    Service_Restarter.ps1

    PowerShell Script

    Service_Restarter.log

    Example Log

     

    Documentation Updates

    This document can be found online:  PS - Service Restarter.  Refer to the online documentation for the most up-to-date version.

    Disclaimer of Warranty,

    THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM “AS IS” WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.

     

    Limitation of Liability,

    IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.