Hi everyone.
I am trying to script SQL database roles as the built in SSMS "Task", "Generate scripts" is able to do it. An example of the output can be found below.
I set the following Scripter options:
$scripter.Options.IncludeDatabaseRoleMemberships = $true
$scripter.Options.Permissions = $true
However I only get the CREATE USER... part. Does any one have an example of how to also get the ALTER ROLE statements?
Kind regards
Bob
USE [TestDB]
GO
CREATE USER [MyDBuser] FOR LOGIN [MyDBuser] WITH DEFAULT_SCHEMA=[dbo]
GO
ALTER ROLE [db_executor] ADD MEMBER [MyDBuser]
GO
ALTER ROLE [db_owner] ADD MEMBER [MyDBuser]
GO
ALTER ROLE [db_backupoperator] ADD MEMBER [MyDBuser]
GO
ALTER ROLE [db_datareader] ADD MEMBER [MyDBuser]
GO
ALTER ROLE [db_datawriter] ADD MEMBER [MyDBuser]
GO