listing database roles granted to database users in sqlserver

The output from this is unlovely, but it does the trick for the time being.


$DatabaseUsers = dir Sqlserver:\sql\$ServerName\$InstanceName\databases\$DatabaseName\Users
foreach ($User in $DatabaseUsers) {"==$User=="; $User.EnumRoles()}

The output looks like this


==[Company\service_account]==
RSExecRole
db_owner
==[Company\user1]==
RSExecRole
db_owner
db_accessadmin
db_securityadmin
db_ddladmin
db_backupoperator
db_datareader
db_datawriter
==[user2]==
==[user3]==
RSExecRole
db_owner
db_ddladmin
db_datareader
db_datawriter

Advertisements