dbatools is a free PowerShell module with over 200 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


Get-DbaLogin

The Get-DbaLogin function returns an SMO Login object for the logins passed, if there are no users passed it will return all logins.

Screenshots

Examples

Get all the logins for a given SQL Server using NT authentication and returns the SMO login objects

Get-DbaLogin -SqlInstance SQl2016

Get all the logins for a given SQL Server using a passed credential object and returns the SMO login objects

Get-DbaLogin -SqlInstance SQl2016 -SqlCredential (Get-Credential sqladmin)

Get specific user objects from the server

Get-DbaLogin -SqlInstance SQl2016 -SqlCredential (Get-Credential sqladmin) -Login dbatoolsuser,TheCaptain

You can also specify more than one server

Get-DbaLogin -SqlInstance sql2014, sql2016 -SqlCredential (Get-Credential sqladmin)

Using Get-DbaLogin on the pipeline to get all locked Logins on sql2016 and sql2014

‘sql2016’, ‘sql2014’ | Get-DbaLogin -SqlCredential (Get-Credential sqladmin) -Locked

Using Get-DbaLogin on the pipeline to get all Disabled logins that have access to sql2016 or sql2014

‘sql2016’, ‘sql2014’ | Get-DbaLogin -SqlCredential (Get-Credential sqladmin) -HasAccess -Disabled

Get-Help

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

Source Code

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

Related commands