Add-DBADbRolemember,dbatools

The below command will create a new user at database level and add that user to the required roles.
cls
$UserName='UserNameHere'
$InstanceName='InstanceNameHere'
New-DbaDbUser -SqlInstance $InstanceName -Database DatbaseNameHere -Username $UserName 
Add-DbaDbRoleMember -SqlInstance $InstanceName `
 -Database DatabaseNameHere `
 -Role "db_ddladmin","db_executor","db_datawriter","db_datareader","db_spexec" `
 -User $UserName -Verbose

Comments

Popular posts from this blog

System.Data.SqlClient.SqlException (0x80131904): Execution Timeout Expired. The timeout period elapsed prior to completion of the operation or the server is not responding. ---> System.ComponentModel.Win32Exception (0x80004005): The wait operation timed out

Pre login Handshake or Connection Timeout Period

Transparent Data Encryption(TDE) with Master Key and Certificate in SQL Server