Sql-server – Problem with Script to Synchronize Login on AlwaysON

sql server 2014

I'm trying to resolve an issue. I've a two nodes with Always On enabled, I want to synchronize user over the nodes. I see that fantastic script.

https://maq.guru/synchronizing-sql-server-logins-in-an-always-on-availability-group/

Only one problem, when an user SQL have Policy enabled tghi script can't change password on other node.

Error message:

Invoke-Sqlcmd : A HASHED password cannot be set for a login that has CHECK_POLICY turned on.
A HASHED password cannot be set for a login that has CHECK_POLICY turned on.
At C:\Users\Administrator\Desktop\AutoCloneLogins.Or.ps1:343 char:17
+ … Invoke-Sqlcmd -Query $Query -ServerInstance $SecondaryRep …
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [Invoke-Sqlcmd], SqlPowerShellSqlExecutionException
+ FullyQualifiedErrorId : SqlError,Microsoft.SqlServer.Management.PowerShell.GetScriptCommand**

Please help me to resolve this issue.

Best Answer

I would suggest using dbatools - Sync-DbaAvailabilityGroup with -Exclude <-- exclude the settings that you dont need to sync.

Honestly, you should sync all e.g. sp_configure, logins, jobs, etc