Author | Frank Henninger (@osiris687) , Andreas Jordan (@JordanOrdix), ordix.de |
Availability | Windows, Linux, macOS |
Want to see the source code for this command? Check out New-DbaDbUser on GitHub.
Want to see the Bill Of Health for this command? Check out New-DbaDbUser.
Creates a new user for the specified database(s).
Creates a new user for the specified database(s) with provided specifications.
New-DbaDbUser
[-SqlInstance] <DbaInstanceParameter[]>
[-SqlCredential <PSCredential>]
[-Database <String[]>]
[-ExcludeDatabase <String[]>]
[-IncludeSystem]
-User <String>
-ExternalProvider
[-DefaultSchema <String>]
[-Force]
[-EnableException]
[-WhatIf]
[-Confirm]
[<CommonParameters>]
New-DbaDbUser
[-SqlInstance] <DbaInstanceParameter[]>
[-SqlCredential <PSCredential>]
[-Database <String[]>]
[-ExcludeDatabase <String[]>]
[-IncludeSystem]
-User <String>
-SecurePassword <SecureString>
[-DefaultSchema <String>]
[-Force]
[-EnableException]
[-WhatIf]
[-Confirm]
[<CommonParameters>]
New-DbaDbUser
[-SqlInstance] <DbaInstanceParameter[]>
[-SqlCredential <PSCredential>]
[-Database <String[]>]
[-ExcludeDatabase <String[]>]
[-IncludeSystem]
-User <String>
[-DefaultSchema <String>]
[-Force]
[-EnableException]
[-WhatIf]
[-Confirm]
[<CommonParameters>]
New-DbaDbUser
[-SqlInstance] <DbaInstanceParameter[]>
[-SqlCredential <PSCredential>]
[-Database <String[]>]
[-ExcludeDatabase <String[]>]
[-IncludeSystem]
[-User <String>]
-Login <String>
[-DefaultSchema <String>]
[-Force]
[-EnableException]
[-WhatIf]
[-Confirm]
[<CommonParameters>]
PS C:\> New-DbaDbUser -SqlInstance sqlserver2014 -Database DB1 -Login user1
Creates a new sql user named user1 for the login user1 in the database DB1.
PS C:\> New-DbaDbUser -SqlInstance sqlserver2014 -Database DB1 -User user1
Creates a new sql user named user1 without login in the database DB1.
PS C:\> New-DbaDbUser -SqlInstance sqlserver2014 -Database DB1 -User user1 -Login login1
Creates a new sql user named user1 for the login login1 in the database DB1.
PS C:\> New-DbaDbUser -SqlInstance sqlserver2014 -Database DB1 -User user1 -Login Login1 -DefaultSchema schema1
Creates a new sql user named user1 for the login login1 in the database DB1 and specifies the default schema to be schema1.
PS C:\> New-DbaDbUser -SqlInstance sqlserver2014 -Database DB1 -User "claudio@********.onmicrosoft.com" -ExternalProvider
Creates a new sql user named 'claudio@********.onmicrosoft.com' mapped to Azure Active Directory (AAD) in the database DB1.
PS C:\> New-DbaDbUser -SqlInstance sqlserver2014 -Database DB1 -Username user1 -Password (ConvertTo-SecureString -String "DBATools" -AsPlainText -Force)
Creates a new contained sql user named user1 in the database DB1 with the password specified.
The target SQL Server instance or instances.
Alias | |
Required | True |
Pipeline | false |
Default Value |
When specified, the user will have this name. If not specified but -Login is used, the user will have the same name as the login.
Alias | Username |
Required | True |
Pipeline | false |
Default Value |
When specified, the user will be associated to this SQL login.
Alias | |
Required | True |
Pipeline | false |
Default Value |
If we need to pass a password to the command, we always use the type securestring and name the parameter SecurePassword. Here we only use the alias for backwords compatibility.
Alias | Password |
Required | True |
Pipeline | false |
Default Value |
When specified, the user will be created for Azure AD Authentication.
Equivalent to T-SQL: 'CREATE USER [claudio@********.onmicrosoft.com] FROM EXTERNAL PROVIDER`
Alias | |
Required | True |
Pipeline | false |
Default Value | False |
Login to the target instance using alternative credentials. Accepts PowerShell credentials (Get-Credential).
Windows Authentication, SQL Server Authentication, Active Directory - Password, and Active Directory - Integrated are all supported.
For MFA support, please use Connect-DbaInstance.
Alias | |
Required | False |
Pipeline | false |
Default Value |
Specifies one or more database(s) to process. If unspecified, all user databases will be processed.
Alias | |
Required | False |
Pipeline | false |
Default Value |
Specifies one or more database(s) to exclude from processing.
Alias | |
Required | False |
Pipeline | false |
Default Value |
If this switch is enabled, also system databases will be processed.
Alias | |
Required | False |
Pipeline | false |
Default Value | False |
The default database schema for the user. If not specified this value will default to dbo.
Alias | |
Required | False |
Pipeline | false |
Default Value | dbo |
If user exists, drop and recreate.
Alias | |
Required | False |
Pipeline | false |
Default Value | False |
By default, when something goes wrong we try to catch it, interpret it and give you a friendly warning message.
This avoids overwhelming you with "sea of red" exceptions, but is inconvenient because it basically disables advanced scripting.
Using this switch turns this "nice by default" feature off and enables you to catch exceptions with your own try/catch.
Alias | |
Required | False |
Pipeline | false |
Default Value | False |
If this switch is enabled, no actions are performed but informational messages will be displayed that explain what would happen if the command were to run.
Alias | wi |
Required | False |
Pipeline | false |
Default Value |
If this switch is enabled, you will be prompted for confirmation before executing any operations that change state.
Alias | cf |
Required | False |
Pipeline | false |
Default Value |