Test‑SqlDscIsDatabase - dsccommunity/SqlServerDsc GitHub Wiki

SYNOPSIS

Tests if a database exists on a SQL Server Database Engine instance.

SYNTAX

Test-SqlDscIsDatabase [-ServerObject] <Server> [-Name] <String> [-Refresh] 
 [<CommonParameters>]

DESCRIPTION

This command tests if a database exists on a SQL Server Database Engine instance.

EXAMPLES

EXAMPLE 1

$serverObject = Connect-SqlDscDatabaseEngine -InstanceName 'MyInstance'
$serverObject | Test-SqlDscIsDatabase -Name 'MyDatabase'

Tests if the database named MyDatabase exists on the instance.

EXAMPLE 2

$serverObject = Connect-SqlDscDatabaseEngine -InstanceName 'MyInstance'
Test-SqlDscIsDatabase -ServerObject $serverObject -Name 'MyDatabase' -Refresh

Tests if the database named MyDatabase exists on the instance, refreshing the server object's databases collection first.

PARAMETERS

-Name

Specifies the name of the database to test for existence.

Type: String
Parameter Sets: (All)
Aliases:

Required: True
Position: 2
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 existence. 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

[Microsoft.SqlServer.Management.Smo.Server]

The server object can be provided via the pipeline to ServerObject.

OUTPUTS

[System.Boolean]

Returns $true if the target object is a database; otherwise, $false.

NOTES

RELATED LINKS

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