dbatools is a free PowerShell module with over 300 SQL Server administration, best practice and migration commands included.

Please note that documentation and command names may be out of date while we work furiously towards 1.0


Exports Windows and SQL Logins to a T-SQL file. Supports SQL Server versions 2000 and above. Migrates logins with SIDs, passwords, defaultdb, server roles & securables, database permissions & securables, login attributes (enforce password policy, expiration, etc).

By default, all logins with the exception of system (####Example Login## and local (SERVERNAME\administrators) logins are exported.

The -Logins and -Exclude parameters are autopopulated for command-line completion and can be used to export only specific logins or exclude specific logins.





To export SQL for the logins in server “sql2005” and write them to the file “C:\temp\sql2005-logins.sql”


To authenticate to sqlserver2014a using SQL Authentication. Exports all logins except for realcajun to C:\temp\logins.sql, and appends to the file if it exists. If not, the file will be created.


To export ONLY logins netnerds and realcajun fron sqlsever2014a to the file C:\temp\logins.sql



From PowerShell, execute Get-Help Export-DbaLogin -Detailed for more information on this function.

Source Code

Want to see the source code? View Export-DbaLogin.ps1 on GitHub

Related commands