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


New-DbaDbUser

Creates a new user for a specified database with provided specifications.

Screenshots

dbatools-New-DbaDbUser

Examples

Creates a new sql user with login named user1 in the specified database.

New-DbaDbUser -SqlInstance sqlserver2014 -Database DB1 -Login user1

Creates a new sql user without login named user1 in the specified database.

New-DbaDbUser -SqlInstance sqlserver2014 -Database DB1 -Username user1

Creates a new sql user named user1 mapped to Login1 in the specified database.

New-DbaDbUser -SqlInstance sqlserver2014 -Database DB1 -Login Login1 -Username user1

Copies users from sqlserver1.DB1 to sqlserver2.DB1. Does not copy permissions!

Get-DbaDatabaseUser -SqlInstance sqlserver1 -Database DB1 | New-DbaDbUser -SqlInstance sqlserver2 -Database DB1

Author

This command was created by Frank Henninger. You can find Frank on Twitter.

Get-Help

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

Source Code

Want to see the source code? View New-DbaDbUser.ps1 on GitHub
 

Related commands