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


Get-DbaOrphanUser

An orphan user is defined by a user that does not have their matching login. (Login property = “”).

Screenshots

dbatools-Get-DbaOrphanUser

Examples

Finds all orphan users without matching Logins in all databases present on server ‘localhost\sql2016’.

Get-DbaOrphanUser -SqlInstance localhost\sql2016

Finds all orphan users without matching Logins in all databases present on server ‘localhost\sql2016’. SQL Server authentication will be used in connecting to the server.

Get-DbaOrphanUser -SqlInstance localhost\sql2016 -SqlCredential $cred

Finds orphan users without matching Logins in the db1 database present on server ‘localhost\sql2016’.

Get-DbaOrphanUser -SqlInstance localhost\sql2016 -Database db1

Author

This command was created by Garry Bargsley. You can find Garry on Twitter and his blog.

Get-Help

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

Source Code

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

Related commands