How to Get Only SQL Server Logins Using Export-DbaLogin

dbatoolsmigrationpowershellsql server

when we run the export-dbalogin, it will will generate a script(.sql) file, which we will run the in the destination server, then the logins will be migrated, but this command will give both windows as well as SQL server logins. I only want SQL server logins.

I tried to use Get-dbalogin to generate a list of SQL server login and kept them in a variable, then I tried to pass that variable to the -login switch in Export-DbaLogin but it is not working.

Thanks In Advance.

Best Answer

As you can see from the Get-DbaLogin source, the -Type parameter accepts a value of 'SQL' to filter to only SQL Logins and exclude AD logins. You can pipe this directly into the Export-DbaLogin function like so...

Get-DbaLogin `
    -Type 'SQL' `
    -SqlInstance localhost | 
Export-DbaLogin `
    -FilePath 'foo.sql'

powershell terminal showing sample code

Note that some logins are excluded by default as shown in the warning feed.