Sync server logins between Primary to Secondary replica in Always On

I got a task from my manager where he asked me to sync logins from Primary to secondary. We can achieve this by using commands from dbatools . We have one command called  Sync-DbaAvailabilityGroup with which we can sync logins from Primary replica to secondary replica.

1) Connect to the secondary replica
2) Run PowerShell ISE as administrator
3) Run the below command in PowerShell

In the below script -SQLInstace should have primary replica.

Get-DbaAvailabilityGroup -SqlInstance RAMESH\UAT | Sync-DbaAvailabilityGroup `-ExcludeType LinkedServers,AgentJob,SpConfigure,CustomErrors,DatabaseMail,LinkedServers,SystemTriggers,DatabaseOwner,AgentCategory,AgentOperator,AgentAlert,AgentProxy,AgentSchedule 

The above command will exclude all the objects that are included to  -ExcludeType parameter and will sync all the logins to the secondary replica. If logins and permissions already exist it will ignore and will synch those only which are not in secondary replica and exists in the primary. 


Comments

Popular posts from this blog

System.Data.SqlClient.SqlException (0x80131904): Execution Timeout Expired. The timeout period elapsed prior to completion of the operation or the server is not responding. ---> System.ComponentModel.Win32Exception (0x80004005): The wait operation timed out

Pre login Handshake or Connection Timeout Period

Transparent Data Encryption(TDE) with Master Key and Certificate in SQL Server