Test‑SqlDscDatabase - dsccommunity/SqlServerDsc GitHub Wiki

SYNOPSIS

Tests if a database on a SQL Server Database Engine instance is in the desired state.

SYNTAX

Test-SqlDscDatabase [-ServerObject] <Server> [-Name] <String> [[-Ensure] <String>] [[-Collation] <String>]
 [[-CompatibilityLevel] <String>] [[-RecoveryModel] <String>] [[-OwnerName] <String>] [-Refresh]
 [<CommonParameters>]

DESCRIPTION

This command tests if a database on a SQL Server Database Engine instance is in the desired state.

EXAMPLES

EXAMPLE 1

$serverObject = Connect-SqlDscDatabaseEngine -InstanceName 'MyInstance'
$serverObject | Test-SqlDscDatabase -Name 'MyDatabase' -Ensure 'Present'

Tests if the database named MyDatabase exists.

EXAMPLE 2

$serverObject = Connect-SqlDscDatabaseEngine -InstanceName 'MyInstance'
$serverObject | Test-SqlDscDatabase -Name 'MyDatabase' -Ensure 'Present' -RecoveryModel 'Simple' -OwnerName 'sa'

Tests if the database named MyDatabase exists and has the specified recovery model and owner.

PARAMETERS

-Collation

The name of the SQL collation that the database should have.

Type: String
Parameter Sets: (All)
Aliases:

Required: False
Position: 4
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-CompatibilityLevel

The version of the SQL compatibility level that the database should have.

Type: String
Parameter Sets: (All)
Aliases:

Required: False
Position: 5
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-Ensure

When set to 'Present', the database must exist. When set to 'Absent', the database must not exist.

Type: String
Parameter Sets: (All)
Aliases:

Required: False
Position: 3
Default value: Present
Accept pipeline input: False
Accept wildcard characters: False

-Name

Specifies the name of the database to test.

Type: String
Parameter Sets: (All)
Aliases:

Required: True
Position: 2
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-OwnerName

Specifies the name of the login that should be the owner of the database.

Type: String
Parameter Sets: (All)
Aliases:

Required: False
Position: 7
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-RecoveryModel

The recovery model that the database should have.

Type: String
Parameter Sets: (All)
Aliases:

Required: False
Position: 6
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-Refresh

Specifies that the ServerObject's databases should be refreshed before testing the database state. This is helpful when databases could have been modified outside of the ServerObject, for example through T-SQL. But on instances with a large amount of databases it might be better to make sure the ServerObject is recent enough.

Type: SwitchParameter
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: False

-ServerObject

Specifies current server connection object.

Type: Server
Parameter Sets: (All)
Aliases:

Required: True
Position: 1
Default value: None
Accept pipeline input: True (ByValue)
Accept wildcard characters: False

CommonParameters

This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters.

INPUTS

OUTPUTS

[System.Boolean]

NOTES

RELATED LINKS

⚠️ **GitHub.com Fallback** ⚠️