dbatools is a free PowerShell module with over 200 SQL Server administration, best practice and migration commands included.

Please note that documentation and command names may be out of date while we work furiously towards 1.0


Remove-DbaDatabase

Drops a database, hopefully even the really stuck ones. Has built in confirmation prompts, so you can be sure of what you’re dropping.

Examples

Prompts then removes the database containeddb on SQL Server sql2016.

Remove-DbaDatabase -SqlInstance sql2016 -Databases containeddb

Prompts then removes the databases containeddb and mydb on SQL Server sql2016.

Remove-DbaDatabase -SqlInstance sql2016 -Databases containeddb, mydb

Does not prompt and swiftly removes containeddb on SQL Server sql2016.

Remove-DbaDatabase -SqlInstance sql2016 -Databases containeddb -Confirm:$false

Get-Help

From PowerShell, execute Get-Help Remove-DbaDatabase -Detailed for more information on this function.

Source Code

Want to see the source code? View Remove-DbaDatabase.ps1 on GitHub
 

Related commands