Why this is a standing problem, not a one-time setup step
An Availability Group replicates the databases in it. Logins live at the server (instance) level, outside any database, so they are never part of AG data movement, contained databases aside. The moment someone creates a login on the current primary, every secondary is out of sync until someone copies it across, matching the SID exactly so it maps back to the database user after failover.
This isn't a one-time migration task. It's recurring: every new application login, every password rotation for a SQL login, every new service account, has to make it to every replica, indefinitely, for as long as the AG exists.
What Copy-DbaLogin actually covers
dbatools' Copy-DbaLogin is the standard tool for this, and it's genuinely solid at what it does: it copies logins between two instances with matching SIDs, so Windows and SQL logins both map correctly on the other side.
Copy-DbaLogin -Source "Node1" -Destination "Node2" -Login "AppSvc", "ReportUser"
What it doesn't do on its own:
- Detect which logins exist on the primary but are missing on a given secondary, you supply the list
- Run on a schedule, it's a manual, one-off invocation
- Know which replica is currently primary, you point it at a specific source and destination yourself
- Distinguish "safe to overwrite" accounts from
saor the SQL Server Agent service account when you do use-Forcefor a password change
-Force to push the new password is correct for the login that changed, and dangerous if it silently overwrites system accounts you didn't mean to touch.
What Sync-sqmLoginsToAlwaysOn and New-sqmAutoLoginSyncJob add
- AG-aware by default. It detects the current primary replica and syncs outward to secondaries, instead of you tracking which node is which after every failover.
-SafeForceMode. Auto-excludessa, the SQL Agent service account, and other system logins from-Forceoverwrites, so a routine password-sync run can't clobber an account that keeps the instance itself running.-ForceIncludeOnly. A whitelist for the opposite case: update exactly these logins' passwords, nothing else, when you do need to push a specific rotation.-BackupLogins. Generates a rollback script before applying changes.New-sqmAutoLoginSyncJob. Creates a SQL Server Agent job on the primary that runs the sync automatically (daily at 2:00 AM by default), so login drift stops being something a human has to remember.
# One-time setup: schedule daily sync on the AG
New-sqmAutoLoginSyncJob -SqlInstance "SQL01" -AvailabilityGroupName "ProdAG"
# Ad-hoc run right now, with a rollback script first
Sync-sqmLoginsToAlwaysOn -SqlInstance "SQL01" -AvailabilityGroupName "ProdAG" `
-Force -SafeForceMode -BackupLogins
Sync-sqmLoginsToAlwaysOn, New-sqmAutoLoginSyncJob, and the rest of sqmSQLTool's AlwaysOn functions are documented in the command reference.
Questions people actually ask
New-sqmAutoLoginSyncJob creates a SQL Server Agent job on the primary replica that runs the sync automatically, so it's a standing job instead of a task someone has to remember after every new login or password change.