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