Script to Start and stop SQL Server role in Failover Cluster

Vijay Kumar 2,036 Reputation points
2023-04-17T21:04:23.1466667+00:00

Hi Team, We are looking for a script to stop and start role in SQL Server failover cluster. Not for stopping and starting SQL services, only roles. Please help us.

SQL Server Other
0 comments No comments
{count} votes

Accepted answer
  1. LiHongMSFT-4306 31,566 Reputation points
    2023-04-18T02:41:23.24+00:00

    Hi @Vijay Kumar Try Start-ClusterGroup and Stop-ClusterGroup using Powershell.

    Best regards,

    Cosmog Hong


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our Documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


1 additional answer

Sort by: Most helpful
  1. Bjoern Peters 8,921 Reputation points
    2023-04-19T21:04:33.43+00:00

    Hi Vijay, Welcome to Q&A Forum; this is a great place to get support, answers, and tips. Thank you for posting your question; I'll be more than glad to help you out.

    The folder in the Failover cluster manager is named "Roles," but in PowerShell (due to historical topics), it is still called "groups," so those two commands Cosmog told you above are correct. Just a snippet as an example from one of my scripts:

    Import-Module FailoverClusters
    Add-Content -Path $LogFileName -Value "Date: $date1" -Encoding ASCII
    Add-Content -Path $LogFileName -Value "Executed By: $admin" -Encoding ASCII
    
    Get-ClusterGroup | Where-Object {$_.Name -like '*SQL*'} | Out-File -append -Encoding ASCII -FilePath $LogFileName
    $clustergroups = Get-ClusterGroup | Where-Object {$_.IsCoreGroup -eq $false}
    
    [...]
    $cg | Move-ClusterGroup -Node $PreferredOwner
    
    

    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!

    0 comments No comments

Your answer

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