New‑SqlDscLogin - dsccommunity/SqlServerDsc GitHub Wiki
Creates a new login on a SQL Server Database Engine instance.
New-SqlDscLogin -ServerObject <Server> -Name <String> [-WindowsUser] [-DefaultDatabase <String>]
[-DefaultLanguage <String>] [-Disabled] [-Force] [-PassThru] [-WhatIf]
[-Confirm] [<CommonParameters>]
New-SqlDscLogin -ServerObject <Server> -Name <String> [-AsymmetricKey] -AsymmetricKeyName <String>
[-DefaultDatabase <String>] [-DefaultLanguage <String>] [-Disabled] [-Force] [-PassThru]
[-WhatIf] [-Confirm] [<CommonParameters>]
New-SqlDscLogin -ServerObject <Server> -Name <String> [-Certificate] -CertificateName <String>
[-DefaultDatabase <String>] [-DefaultLanguage <String>] [-Disabled] [-Force] [-PassThru]
[-WhatIf] [-Confirm] [<CommonParameters>]
New-SqlDscLogin -ServerObject <Server> -Name <String> [-SqlLogin] -SecurePassword <SecureString>
[-DefaultDatabase <String>] [-DefaultLanguage <String>] [-IsHashed] [-Disabled] [-Force] [-PassThru]
[-WhatIf] [-Confirm] [<CommonParameters>]
New-SqlDscLogin -ServerObject <Server> -Name <String> [-SqlLogin] -SecurePassword <SecureString>
[-DefaultDatabase <String>] [-DefaultLanguage <String>] [-PasswordExpirationEnabled] [-PasswordPolicyEnforced]
[-MustChangePassword] [-Disabled] [-Force] [-PassThru] [-WhatIf]
[-Confirm] [<CommonParameters>]
New-SqlDscLogin -ServerObject <Server> -Name <String> [-WindowsGroup] [-DefaultDatabase <String>]
[-DefaultLanguage <String>] [-Disabled] [-Force] [-PassThru] [-WhatIf]
[-Confirm] [<CommonParameters>]
This command creates a new login on a SQL Server Database Engine instance. The login can be a SQL Server login, a Windows login (user or group), a certificate-based login, or an asymmetric key-based login.
$serverObject = Connect-SqlDscDatabaseEngine -InstanceName 'MyInstance'
$securePassword = ConvertTo-SecureString -String 'MyPassword123!' -AsPlainText -Force
$serverObject | New-SqlDscLogin -Name 'MyLogin' -SqlLogin -SecurePassword $securePassword
Creates a new SQL Server login named 'MyLogin' with the specified password.
$serverObject = Connect-SqlDscDatabaseEngine -InstanceName 'MyInstance'
$securePassword = ConvertTo-SecureString -String 'MyPassword123!' -AsPlainText -Force
$serverObject | New-SqlDscLogin -Name 'MyLogin' -SqlLogin -SecurePassword $securePassword -MustChangePassword
Creates a new SQL Server login named 'MyLogin' with a SecureString password that must be changed on first login.
$serverObject = Connect-SqlDscDatabaseEngine -InstanceName 'MyInstance'
$serverObject | New-SqlDscLogin -Name 'DOMAIN\MyUser' -WindowsUser
Creates a new Windows user login for 'DOMAIN\MyUser'.
$serverObject = Connect-SqlDscDatabaseEngine -InstanceName 'MyInstance'
$serverObject | New-SqlDscLogin -Name 'DOMAIN\MyGroup' -WindowsGroup
Creates a new Windows group login for 'DOMAIN\MyGroup'.
$serverObject = Connect-SqlDscDatabaseEngine -InstanceName 'MyInstance'
$serverObject | New-SqlDscLogin -Name 'MyCertLogin' -Certificate -CertificateName 'MyCertificate'
Creates a new certificate-based login using the specified certificate.
$serverObject = Connect-SqlDscDatabaseEngine -InstanceName 'MyInstance'
$hashedPassword = ConvertTo-SecureString -String '0x020012345678...' -AsPlainText -Force
$serverObject | New-SqlDscLogin -Name 'MyHashedLogin' -SqlLogin -SecurePassword $hashedPassword -IsHashed
Creates a new SQL Server login with a pre-hashed password. Note that password policy options (PasswordExpirationEnabled, PasswordPolicyEnforced, MustChangePassword) cannot be used with hashed passwords.
$serverObject = Connect-SqlDscDatabaseEngine -InstanceName 'MyInstance'
$securePassword = ConvertTo-SecureString -String 'MyPassword123!' -AsPlainText -Force
$loginObject = $serverObject | New-SqlDscLogin -Name 'MyLogin' -SqlLogin -SecurePassword $securePassword -PassThru
Creates a new SQL Server login and returns the Login object.
$serverObject = Connect-SqlDscDatabaseEngine -InstanceName 'MyInstance'
$serverObject | New-SqlDscLogin -Name 'MyAsymmetricKeyLogin' -AsymmetricKey -AsymmetricKeyName 'MyAsymmetricKey'
Creates a new asymmetric key-based login using the specified asymmetric key.
$serverObject = Connect-SqlDscDatabaseEngine -InstanceName 'MyInstance'
$serverObject | New-SqlDscLogin -Name 'MyAsymmetricKeyLogin' -AsymmetricKey -AsymmetricKeyName 'MyAsymmetricKey' -PassThru
Creates a new asymmetric key-based login and returns the Login object.
$serverObject = Connect-SqlDscDatabaseEngine -InstanceName 'MyInstance'
$securePassword = ConvertTo-SecureString -String 'NewPassword123!' -AsPlainText -Force
$serverObject | New-SqlDscLogin -Name 'ExistingLogin' -SqlLogin -SecurePassword $securePassword -Force
Creates a SQL Server login named 'ExistingLogin' without confirmation prompts. Note: If the login already exists, the command throws a terminating error.
$serverObject = Connect-SqlDscDatabaseEngine -InstanceName 'MyInstance'
$securePassword = ConvertTo-SecureString -String 'MyPassword123!' -AsPlainText -Force
$serverObject | New-SqlDscLogin -Name 'DisabledLogin' -SqlLogin -SecurePassword $securePassword -Disabled
Creates a new SQL Server login in a disabled state.
$serverObject = Connect-SqlDscDatabaseEngine -InstanceName 'MyInstance'
$serverObject | New-SqlDscLogin -Name 'DOMAIN\DisabledUser' -WindowsUser -Disabled -PassThru
Creates a new disabled Windows user login and returns the Login object.
Specifies that an asymmetric key-based login should be created.
Type: SwitchParameter
Parameter Sets: AsymmetricKey
Aliases:
Required: True
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: FalseSpecifies the asymmetric key name when creating an asymmetric key-based login.
Type: String
Parameter Sets: AsymmetricKey
Aliases:
Required: True
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: FalseSpecifies that a certificate-based login should be created.
Type: SwitchParameter
Parameter Sets: Certificate
Aliases:
Required: True
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: FalseSpecifies the certificate name when creating a certificate-based login.
Type: String
Parameter Sets: Certificate
Aliases:
Required: True
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: FalseSpecifies the default database for the login. If not specified, 'master' will be used as the default database.
Type: String
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: Master
Accept pipeline input: False
Accept wildcard characters: FalseSpecifies the default language for the login.
Type: String
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: FalseSpecifies whether the login should be created in a disabled state.
Type: SwitchParameter
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: FalseSpecifies that the login should be created without any confirmation.
Type: SwitchParameter
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: FalseSpecifies whether the provided password is already hashed. Only applies when creating a SQL Server login.
Type: SwitchParameter
Parameter Sets: SqlLoginHashed
Aliases:
Required: True
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: FalseSpecifies whether the user must change the password on next login. Only applies when creating a SQL Server login.
Type: SwitchParameter
Parameter Sets: SqlLogin
Aliases:
Required: False
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: FalseSpecifies the name of the login to be created.
Type: String
Parameter Sets: (All)
Aliases:
Required: True
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: FalseIf specified, the created login object will be returned.
Type: SwitchParameter
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: FalseSpecifies whether password expiration is enabled for SQL Server logins. Only applies when creating a SQL Server login.
Type: SwitchParameter
Parameter Sets: SqlLogin
Aliases:
Required: False
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: FalseSpecifies whether password policy is enforced for SQL Server logins. Only applies when creating a SQL Server login.
Type: SwitchParameter
Parameter Sets: SqlLogin
Aliases:
Required: False
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: FalseSpecifies the password as a SecureString for SQL Server logins. This parameter is required when creating a SQL Server login.
Type: SecureString
Parameter Sets: SqlLoginHashed, SqlLogin
Aliases:
Required: True
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: FalseSpecifies current server connection object.
Type: Server
Parameter Sets: (All)
Aliases:
Required: True
Position: Named
Default value: None
Accept pipeline input: True (ByValue)
Accept wildcard characters: FalseSpecifies that a SQL Server login should be created.
Type: SwitchParameter
Parameter Sets: SqlLoginHashed, SqlLogin
Aliases:
Required: True
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: FalseSpecifies that a Windows group login should be created.
Type: SwitchParameter
Parameter Sets: WindowsGroup
Aliases:
Required: True
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: FalseSpecifies that a Windows user login should be created.
Type: SwitchParameter
Parameter Sets: WindowsUser
Aliases:
Required: True
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: FalsePrompts you for confirmation before running the cmdlet.
Type: SwitchParameter
Parameter Sets: (All)
Aliases: cf
Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: FalseShows what would happen if the cmdlet runs. The cmdlet is not run.
Type: SwitchParameter
Parameter Sets: (All)
Aliases: wi
Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: FalseThis cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters.
This command has the confirm impact level set to medium since a login is created but by default it does not have any special permissions.