Login Resource
Synopsis
Manages SQL Server logins, including SQL authentication, Windows authentication, password policies, and server role membership.
Type
Capabilities
- Get
- Set
- Delete
- Export
Properties
Connection properties
serverInstance
SQL Server instance name. Use . or (local) for the default instance, or
server\instance for named instances.
connectUsername
Username for SQL authentication. Omit for Windows authentication.
connectPassword
Password for SQL authentication.
Login properties
name
Name of the login.
loginType
Login type: SqlLogin, WindowsUser, WindowsGroup, Certificate,
AsymmetricKey, ExternalUser, or ExternalGroup.
password
Password. Required when creating SQL logins.
defaultDatabase
Default database for the login.
language
Default language.
disabled
Whether the login is disabled.
passwordExpirationEnabled
Whether password expiration policy is enforced.
passwordPolicyEnforced
Whether password policy is enforced.
mustChangePassword
Whether the user must change the password at next login.
denyWindowsLogin
Whether to deny Windows login access. Only applies to Windows logins.
serverRoles
Server roles to assign. Values must be unique.
_purge
When true, removes roles not in serverRoles. When false, only adds roles.
Read-only properties
createDate
Creation date of the login.
dateLastModified
Date the login was last modified.
hasAccess
Whether the login has server access.
isLocked
Whether the login is locked out.
isPasswordExpired
Whether the password has expired.
isSystemObject
Whether this is a system login.
DSC properties
_exist
Whether the login should exist. Defaults to true.
Examples
Example 1 — Get a login
Example 2 — Create a SQL login
Example 3 — Delete a login
Example 4 — Configuration document
$schema: https://aka.ms/dsc/schemas/v3/bundled/config/document.json
resources:
- name: Application login
type: OpenDsc.SqlServer/Login
properties:
serverInstance: "."
name: AppUser
loginType: SqlLogin
password: "[parameter('appUserPassword')]"
defaultDatabase: AppDb
passwordPolicyEnforced: true
passwordExpirationEnabled: true
serverRoles:
- public
Exit codes
| Code | Description |
|---|---|
| 0 | Success |
| 1 | Error |
| 2 | Invalid JSON |
| 3 | Invalid argument |
| 4 | Unauthorized access |
| 5 | Invalid operation |