I have tried different scripts to transfer the logins with permissions, in all of that I like the DBATools command (Export-DBAlogin). which is easy and simple. If DBATools is not installed on your machine, you can do that offline with simple steps
- Download DBATools from https://dbatools.io/offline/ . once the file has been downloaded unzip and place on below folders C:\Temp
- copy the same folder to one of the directories in your
$env:PSModulePath(type$env:PSModulePathat the prompt and press enter). This will allow PowerShell to autoload the module, saving you from having to Import-Module each time you start a new session. - from PS > import-module dbatools ( you may need to grant Set-ExecutionPolicy Unrestricted)
once the installation is completed, use below command to export the logins.
Export-dbalogin -sqlinstance servername -filepath ‘filepath’
— if you see execution policy-related errors while importing the DBATools module, try below one
set-executionpolicy -scope process -executionpolicy bypass
import-module DBATools