Created
April 8, 2024 07:40
-
-
Save ctrl-freak/922580419cceb1557cb9d237a5b562c6 to your computer and use it in GitHub Desktop.
Generate SQL to create MSSQL logins with same SID and password
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- SQL Server Logins | |
select | |
'create login [' + sp.[name] + '] with password=0x' + CONVERT(nvarchar(max), l.password_hash, 2) + ' hashed, sid=0x' + convert(nvarchar(2000), sp.[sid], 2) + ', default_language = [us_english];' | |
from | |
master.sys.server_principals sp | |
inner join master.sys.sql_logins l on sp.[sid] = l.[sid] | |
where | |
sp.type_desc = 'SQL_LOGIN' | |
and sp.is_disabled = 0 | |
and sp.default_language_name = 'us_english' -- helps target the specifically created logins | |
order by | |
sp.[name] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment