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

Get database roles on a Sql instance.

Default output includes columns SQLServer, Database, Role.

Screenshots

dbatools-Get-DbaDbRole

Examples

Returns a custom object displaying SQLServer, Database, Role for all DatabaseRoles on sql instance ServerA.

Get-DbaDbRole -SqlInstance ServerA

Returns a gridview displaying SQLServer, Database, Role for all DatabaseRoles on sql instance ServerA.

Get-DbaDbRole -SqlInstance ServerA | Out-Gridview

Returns SQLServer, Database, Role for DatabaseRoles on sql instance ServerB\sql16, except those in databases DBADB and TestDB.

Get-DbaDbRole -SqlInstance ServerB\sql16 -ExcludeDatabase DBADB,TestDB

Returns SQLServer, Database, Role for DatabaseRoles on sql instances ServerA and ServerB\sql16.

‘ServerB\sql16′,’ServerA’ | Get-DbaDbRole

Returns SQLServer, Database, Role for DatabaseRoles in database AccountingDB on sql instance ServerB\sql16.

Get-DbaDbRole -SqlInstance ServerB\sql16 -Database AccountingDB

Returns SQLServer, Database, Role for DatabaseRoles on sql instance ServerB\sql16, but not the fixed roles.

Get-DbaDbRole -SqlInstance ServerB\sql16 -ExcludeFixedRoles

Author

This command was created by Klaas Vandenberghe. You can find Klaas on Twitter.

Get-Help

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

Source Code

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

Related commands