How to script logins with the original password HASH and original SID

A quick tip useful to avoid problems during migrations.
This query allow to script instance users with orginal SID and password HASH.

This can be very useful to transfer logins to a new or different instance. All informations come from master database catalog. You have to be member of sysadmin role to run correctly this script. Users with noadmin grant we’ll have no or uncomplete output result.

convert(varchar(50),'CREATE LOGIN [' + name + '] with password='),CAST(password AS VARBINARY(26)),
from sys.syslogins  where password is not null

Be the first to comment

Leave a Reply

Your email address will not be published.