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-DbaServerRole

Gets the list of server-level roles for SQL Server instance.

Screenshots

dbatools-Get-DbaServerRole

Examples

Outputs list of server-level roles and logins that are members for sql2016a instance.

Get-DbaServerRole -SqlInstance sql2016a

Outputs members of sysadmin server-level role on sql2016a instance.

Get-DbaServerRole -SqlInstance sql2016a -Role sysadmin

Outputs the server-level role(s) that are not fixed roles on sql2017a instance.

Get-DbaServerRole -SqlInstance sql2017a -ExcludeFixedRole

Outputs the server-level role(s) that the login Bob is a member of on sql2016a instance.
If Bob is not a member of any role, no output is returned.

Get-DbaServerRole -SqlInstance sql2016a -Login Bob

Outputs the server-level role sysadmin with the login Bob as a member on sql2016a instance.
If Bob is not a member of that role, no output is returned.

Get-DbaServerRole -SqlInstance sql2016a -Role sysadmin -Login Bob

Author

This command was created by Shawn Melton. You can find Shawn on Twitter and his blog.

Get-Help

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

Source Code

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

Related commands