Skip to content

Latest commit

 

History

History
161 lines (124 loc) · 3.89 KB

File metadata and controls

161 lines (124 loc) · 3.89 KB

DSC Resource 'SqlRoles'

SqlRoles manages SQL Server roles and their membership.

When to use 'SqlRoles'

Use this resource when you need to create custom SQL Server roles or manage membership of built-in server roles (sysadmin, dbcreator, securityadmin, etc.). Use this for implementing role-based access control at the SQL Server level.

The SqlRole DSC resource is used to create a server role, when Ensure is set to Present, or remove a server role, when Ensure is set to Absent. The resource also manages members in both built-in and user created server roles.

When the target role is sysadmin the DSC resource will prevent the user sa from being removed. This is done to keep the DSC resource from throwing an error since SQL Server does not allow this user to be removed.

Source

DSC Resource

Documentation

Requirements
  • Target machine must be running Windows Server 2012 or later.

  • Target machine must be running SQL Server Database Engine 2012 or later.

Table 1. Attributes of category 'SqlRoles'
Parameter Attribute DataType Description Allowed Values

DefaultInstanceName

String

Default SQL InstanceName
If the InstanceName of a value is not explicitly set, the DefaultInstanceName will be used.

Default: MSSQLSERVER

Values

Mandatory

Hashtable[]

List of SQL roles.

Table 2. Attributes of category 'SqlRoles/Values'
Parameter Attribute DataType Description Allowed Values

ServerRoleName

Key

String

The name of of SQL Server Database Engine role to add or remove.

InstanceName

Key

String

The name of the SQL Server instance to be configured.

ServerName

String

The host name of the SQL Server to be configured.

Default value is the current computer name.

Members

String[]

The members the server role should have.

This parameter will replace all the current server role members with the specified members.

MembersToInclude

String[]

The members the server role should include.

This parameter will only add members to a server role. Can not be used at the same time as parameter Members.

MembersToExclude

String[]

The members the server role should exclude.

This parameter will only remove members from a server role. Can only be used when parameter Ensure is set to Present. Can not be used at the same time as parameter Members.

Ensure

String

Determines whether the role should be added (Present) or removed (Absent).

  • Present

  • Absent

Example
SqlRoles:
  Roles:
    - ServerRoleName: sysadmin
      MembersToInclude: install
      InstanceName: MSSQLSERVER
    - ServerRoleName: AdminSqlforBI
      MembersToInclude:
        - CONTOSO\John
        - CONTOSO\Kelly
      ServerName: sqltest.company.local
      InstanceName: DSC