Skip to content

SPDatabaseAAG

dscbot edited this page Mar 17, 2023 · 18 revisions

SPDatabaseAAG

Parameters

Parameter Attribute DataType Description Allowed Values
DatabaseName Key String The name of the database to put in the AlwaysOn group
AGName Required String Name of the AlwaysOn group on the SQL server - this must already exist
FileShare Write String The fileshare to use for the SQL backup when adding to the group
Ensure Write String Present if the database should be in this AlwaysOn group, or Absent if it should not be in the group Present, Absent

Description

Type: Distributed Requires CredSSP: No

This resource will allow specifying which SQL Server AlwaysOn Availability group a resource should be in. This resource does not configure the Availability Groups on SQL Server, they must already exist. It simply adds the specified database to the group.

You can add a single database name by specifying the database name, or multiple databases by specifying wildcards. For example: SP_Content* or Content

Important: This resource requires the April 2014 CU to be installed. The required cmdlets have been added in this CU: http://support.microsoft.com/kb/2880551

The default value for the Ensure parameter is Present. When not specifying this parameter, the content database is added to the AAG.

Note: By design the Add-DatabaseToAvailabilityGroup cmdlet updates the database connection string to the specified availability group. If this is NOT what you want (for example: You are using SQL aliasses which point to the AG listener), you should NOT use this resource.

Examples

Example 1

This example takes an existing SharePoint database and puts it in to the specified AlwaysOn Availability Group (AAG).

Configuration Example
{
    param
    (
        [Parameter(Mandatory = $true)]
        [PSCredential]
        $SetupAccount
    )

    Import-DscResource -ModuleName SharePointDsc

    node localhost
    {
        SPDatabaseAAG ConfigDBAAG
        {
            DatabaseName         = "SP_Config"
            AGName               = "MyAvailabilityGroup"
            FileShare            = "\\SQL\Backups"
            PsDscRunAsCredential = $SetupAccount
        }
    }
}

Example 2

This example takes existing SharePoint databases, based on the database name pattern, and puts them in to the specified AlwaysOn Availability Group (AAG).

Configuration Example
{
    param
    (
        [Parameter(Mandatory = $true)]
        [PSCredential]
        $SetupAccount
    )

    Import-DscResource -ModuleName SharePointDsc

    node localhost
    {
        SPDatabaseAAG ConfigDBAAG
        {
            DatabaseName         = "*Content*"
            AGName               = "MyAvailabilityGroup"
            FileShare            = "\\SQL\Backups"
            PsDscRunAsCredential = $SetupAccount
        }
    }
}

Example 3

This example removes a database from the specified AlwaysOn Availability Group (AAG)

Configuration Example
{
    param
    (
        [Parameter(Mandatory = $true)]
        [PSCredential]
        $SetupAccount
    )

    Import-DscResource -ModuleName SharePointDsc

    node localhost
    {
        SPDatabaseAAG ConfigDBAAG
        {
            DatabaseName         = "SP_Config"
            AGName               = "MyAvailabilityGroup"
            Ensure               = "Absent"
            PsDscRunAsCredential = $SetupAccount
        }
    }
}
Clone this wiki locally