commands

^

Mount-DbaDatabase

Author Chrissy LeMaire (@cl), netnerds.net
Availability Windows, Linux, macOS

 

Aliases : Attach-DbaDatabase

Want to see the source code for this command? Check out Mount-DbaDatabase on GitHub.
Want to see the Bill Of Health for this command? Check out Mount-DbaDatabase.

Synopsis

Attach a SQL Server Database - aliased to Attach-DbaDatabase

Description

This command will attach a SQL Server database.

Syntax

Mount-DbaDatabase
    [-SqlInstance] <DbaInstanceParameter[]>
    [[-SqlCredential] <PSCredential>]
    [-Database] <String[]>
    [[-FileStructure] <StringCollection>]
    [[-DatabaseOwner] <String>]
    [[-AttachOption] <String>]
    [-EnableException]
    [-WhatIf]
    [-Confirm]
    [<CommonParameters>]

 

Examples

 

Example: 1
PS C:\> $fileStructure = New-Object System.Collections.Specialized.StringCollection
PS C:\> $fileStructure.Add("E:\archive\example.mdf")
PS C:\> $filestructure.Add("E:\archive\example.ldf")
PS C:\> $filestructure.Add("E:\archive\example.ndf")
PS C:\> Mount-DbaDatabase -SqlInstance sql2016 -Database example -FileStructure $fileStructure

Attaches a database named "example" to sql2016 with the files "E:\archive\example.mdf", "E:\archive\example.ldf" and "E:\archive\example.ndf". The database owner will be set to sa and the attach
option is None.

Example: 2
PS C:\> Mount-DbaDatabase -SqlInstance sql2016 -Database example

Since the FileStructure was not provided, this command will attempt to determine it based on backup history. If found, a database named example will be attached to sql2016.

Example: 3
PS C:\> Mount-DbaDatabase -SqlInstance sql2016 -Database example -WhatIf

Shows what would happen if the command were executed (without actually performing the command)

Required Parameters

-SqlInstance

The target SQL Server instance or instances.

Alias
Required True
Pipeline true (ByValue)
Default Value
-Database

The database(s) to attach.

Alias
Required True
Pipeline false
Default Value

Optional Parameters

-SqlCredential

Login to the target instance using alternative credentials. Accepts PowerShell credentials (Get-Credential).
Windows Authentication, SQL Server Authentication, Active Directory - Password, and Active Directory - Integrated are all supported.
For MFA support, please use Connect-DbaInstance.

Alias
Required False
Pipeline false
Default Value
-FileStructure

A StringCollection object value that contains a list database files. If FileStructure is not specified, BackupHistory will be used to guess the structure.

Alias
Required False
Pipeline false
Default Value
-DatabaseOwner

Sets the database owner for the database. The sa account (or equivalent) will be used if DatabaseOwner is not specified.

Alias
Required False
Pipeline false
Default Value
-AttachOption

An AttachOptions object value that contains the attachment options. Valid options are "None", "RebuildLog", "EnableBroker", "NewBroker" and "ErrorBrokerConversations".

Alias
Required False
Pipeline false
Default Value None
Accepted Values None,RebuildLog,EnableBroker,NewBroker,ErrorBrokerConversations
-EnableException

By default, when something goes wrong we try to catch it, interpret it and give you a friendly warning message.
This avoids overwhelming you with "sea of red" exceptions, but is inconvenient because it basically disables advanced scripting.
Using this switch turns this "nice by default" feature off and enables you to catch exceptions with your own try/catch.

Alias
Required False
Pipeline false
Default Value False
-WhatIf

If this switch is enabled, no actions are performed but informational messages will be displayed that explain what would happen if the command were to run.

Alias wi
Required False
Pipeline false
Default Value
-Confirm

If this switch is enabled, you will be prompted for confirmation before executing any operations that change state.

Alias cf
Required False
Pipeline false
Default Value