Share via

Start and stop SQL Server cluster roles using script

Vijay Kumar 2,061 Reputation points
2023-03-20T05:20:03.32+00:00

Hi Team,

We have around 5 SQL Server clusters (Active/Passive)

How to remotely bring SQL Cluster roles offline/online either using PowerShell?

Each server contains multiple SQL instances.

Environment:

Windows Server 2019

SQL Server 2017

Windows for business | Windows Server | User experience | PowerShell
0 comments No comments

1 answer

Sort by: Most helpful
  1. Bjoern Peters 8,921 Reputation points
    2023-03-20T12:38:51.99+00:00

    Hi Vijay,

    I would suggest using the PowerShell module dbatools

    https://dbatools.io/commands/#WSFC

    I would proceed as follows:

    • Create a text file containing all Cluster names
    • step through the file
    • get all resource groups that are relevant (like name containing a string %SQL%)
    • Restart the whole group, move the group, or restart just the SQL Server engine
    • Run a loop that connects to that SQL Server instance to check the availability

    Here is a basic blog post from Rob on how to use dbatools to find and restart SQL Server services

    https://sqldbawithabeard.com/2018/12/03/getting-sql-services-starting-stopping-and-restarting-them-with-dbatools/

    I hope my answer is helpful to you,

    Your

    Bjoern Peters

    If the reply was helpful, please upvote and/or accept it as an answer, as this helps others in the community with similar questions. Thanks!

    Was this answer helpful?


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.